Einführung in APIs mit Python
Chris Ramakers
Engineering Manager


1XX: Informative Antworten2XX: Erfolgreiche Antworten3XX: Umleitungen4XX: Client-Fehler5XX: Server-Fehler200: OK404: Nicht gefunden500: Interner Serverfehler
key1: Value 1
key2: Value 2

accept: application/json hinzucontent-type: application/json# Header zu einer Anfrage hinzufügen
response = requests.get(
'https://api.datacamp.com',
headers={'accept':'application/json'}
)
# Response-Header lesen
response.headers['content-type']
'application/json'
response.headers.get('content-type')
'application/json'
# Auf den Statuscode zugreifen response = requests.get('https://api.datacamp.com/users/12')response.status_code == 200
True
# Statuscodes mit requests.codes nachschlagen response = requests.get('https://api.datacamp.com/this/is/the/wrong/path')response.status_code == requests.codes.not_found
True
Einführung in APIs mit Python