Python ile API'lere Giriş
Chris Ramakers
Engineering Manager


1XX: Bilgilendirici yanıtlar2XX: Başarılı yanıtlar3XX: Yönlendirme iletileri4XX: İstemci hatası yanıtları5XX: Sunucu hatası yanıtları200: OK404: Not Found500: Internal Server Error
key1: Değer 1
key2: Değer 2

accept: application/json başlığını eklercontent-type: application/json başlığıyla yanıt verir# Bir isteğe başlık ekleme
response = requests.get(
'https://api.datacamp.com',
headers={'accept':'application/json'}
)
# Yanıt başlıklarını okuma
response.headers['content-type']
'application/json'
response.headers.get('content-type')
'application/json'
# Durum koduna erişme response = requests.get('https://api.datacamp.com/users/12')response.status_code == 200
True
# requests.codes ile durum kodlarını bulma response = requests.get('https://api.datacamp.com/this/is/the/wrong/path')response.status_code == requests.codes.not_found
True
Python ile API'lere Giriş