Nexus Learn

Log in · Create free account

Module 6: Calling an AI service from Python · 10 min

Web requests and APIs

An API (application programming interface) lets one program talk to another over the internet. The requests package sends the message and reads the reply.

import requests

response = requests.get("https://api.github.com", timeout=10)
print(response.status_code)   # 200 means success
data = response.json()        # reply text -> Python data
print(list(data)[:3])
Status codeMeaning
200OK
400Your request was wrong
401 / 403Not allowed (check your key)
429Too many requests, slow down
500Problem on the server

Always set a timeout, and check the status code before using the reply.

(free account needed to save progress)

← Making charts clear and honest  |  Keeping API keys safe →