2020-12-08 python►library python requests 安装 1$ pip3 install requests 引入 1import requests 请求 头 12headers = {'user-agent': '...'}requests.get(url, headers=headers) 参数 12345678# Getpayload = {'key1': 'value1', 'key2': ['value2', 'value3']}r = requests.get(url, params=payload)# Post Jsondata = {'key': 'value'}r = requests.post(url, data=json.dumps(data), headers=headers) # ORr = requests.post(url, json=data) 读取 12345678910111213141516171819# 返回码r.status_code# Json 数据r.json()# 读取二进制数据r.content# 读取图片from PIL import Imagefrom io import BytesIOi = Image.open(BytesIO(r.content))# 保存到文件with open(filename, 'wb') as fd: for chunk in r.iter_content(chunk_size=128): fd.write(chunk) Newer python virtualenv Older 树莓派 GPIO