You can download this code by clicking the button below.
This code is now available for download.
This function fetches a random quote from quotable.io API and returns the quote.
Technology Stack : Requests, JSON
Code Type : Function
Code Difficulty : Intermediate
import requests
import json
from random import choice
def get_random_quote():
quote_url = 'https://api.quotable.io/random'
response = requests.get(quote_url)
if response.status_code == 200:
return response.json().get('content')
else:
return "Failed to fetch quote."