Python 中的 API 入门
Chris Ramakers
Engineering Manager


1XX:信息性响应2XX:成功响应3XX:重定向4XX:客户端错误5XX:服务器错误200:OK404:Not Found500:Internal Server Error
key1: 值 1
key2: 值 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 入门