1、请求携带参数的方式
1、带数据的post data=字典对象
2、带header的post headers=字典对象
3、带json的post json=json对象
4、带参数的post params=字典对象
5、普通文件上传 files= files = {'file':open('filaname.txt','rb')}
6、定制化文件上传 files= files = {'file':('filaname.png',open('filaname.png','rb'),'image/png')}
7、多文件上传 files= files={'file':('filaname.png',open('filaname.png','rb'),'image/png')}

#普通上传
files = {'file':open('test.txt','rb')}

#自定义文件名,文件类型、请求头
files = {'file':('test.png',open('test.png','rb'),'image/png')}

#多文件上传
files = [('file1',('test.txt',open('test.txt', 'rb'))),('file2', ('test.png', open('test.png', 'rb')))]
r = requests.post(url,files=files)

#流式上传
with open( 'test.txt' ) as f:
r = requests.post(url,data = f)

#将RequestsCookieJar转换成字典
c = requests.utils.dict_from_cookiejar(r.cookies)


#方法一:简单发送
# cookies = {"aaa":"bbb"}
# r = requests.get(url,cookies=cookies)
# print r.text

#方法二:复杂发送
s = requests.session()
c = requests.cookies.RequestsCookieJar()
c.set('c-name','c-value',path='/xxx/uuu',domain='.test.com')
s.cookies.update(c)

 

2、请求中的特殊参数
#禁止自动重定向
allow_redirects=False

#超时时间
timeout=None

#去掉ssl验证
verify=False

#去掉警告提示
urllib3.disable_warnings()

#响应时间
res.elapsed.total_seconds()

 

posted on 2018-06-17 10:50  新美好时代  阅读(179)  评论(0编辑  收藏  举报