You can download this code by clicking the button below.
This code is now available for download.
This function fetches a random user's details from the randomuser.me API and returns them.
Technology Stack : requests
Code Type : Function
Code Difficulty : Intermediate
import requests
import random
def fetch_random_user():
# This function fetches a random user from the randomuser.me API and returns their details.
url = 'https://randomuser.me/api/'
response = requests.get(url)
if response.status_code == 200:
user_data = response.json()
return user_data['results'][0]
else:
return None
# Code information