官方网址:

http://docs.python-requests.org/en/master/

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

from requests.auth import HTTPBasicAuth
r = requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))
r.encoding = 'utf-8'
print r.status_code
print r.text
print r.json()

r = requests.post(url, json=json_dict, headers=headers)

# 保持response流,保证接收完整
with requests.get('https://httpbin.org/get', stream=True) as r:
    # Do things with the response here.

# 上传文件
with open('massive-body', 'rb') as f:
    requests.post('http://some.url/streamed', data=f)

# 上传多个文件
url = 'https://httpbin.org/post'
multiple_files = [
        ('images', ('foo.png', open('foo.png', 'rb'), 'image/png')),
        ('images', ('bar.png', open('bar.png', 'rb'), 'image/png'))]
r = requests.post(url, files=multiple_files)
r.text

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄