Úvod do API v Pythonu
Chris Ramakers
Engineering Manager


1XX: Informační odpovědi2XX: Úspěšné odpovědi3XX: Přesměrování4XX: Chyby klienta5XX: Chyby serveru200: OK404: Nenalezeno500: Interní chyba serveru
key1: Value 1
key2: Value 2

accept: application/json k požadavkucontent-type: application/json# Adding headers to a request
response = requests.get(
'https://api.datacamp.com',
headers={'accept':'application/json'}
)
# Reading response headers
response.headers['content-type']
'application/json'
response.headers.get('content-type')
'application/json'
# Accessing the status code response = requests.get('https://api.datacamp.com/users/12')response.status_code == 200
True
# Looking up status codes using requests.codes response = requests.get('https://api.datacamp.com/this/is/the/wrong/path')response.status_code == requests.codes.not_found
True
Úvod do API v Pythonu