Python API 入門
Chris Ramakers
Engineering Manager


1XX:資訊回應2XX:成功回應3XX:重新導向4XX:用戶端錯誤5XX:伺服器錯誤200:OK404:Not Found500:Internal Server Error
key1: Value 1
key2: Value 2

accept: application/json 標頭content-type: application/json 標頭回應# 在請求中加入標頭
response = requests.get(
'https://api.datacamp.com',
headers={'accept':'application/json'}
)
# 讀取回應標頭
response.headers['content-type']
'application/json'
response.headers.get('content-type')
'application/json'
# 取得狀態碼 response = requests.get('https://api.datacamp.com/users/12')response.status_code == 200
True
# 使用 requests.codes 查詢狀態碼 response = requests.get('https://api.datacamp.com/this/is/the/wrong/path')response.status_code == requests.codes.not_found
True
Python API 入門