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