8

Python爬虫编程思想(19):使用urllib3上传文件与处理超时

 2 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/120146284
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

目录

1. 上传文件

2. 超时处理


1. 上传文件

        客户端浏览器向服务端发送HTTP请求时有一类特殊的请求,就是上传文件,为什么特殊呢?因为发送其他值时,可能是以字节为单位的,而上传文件时,可能是以KB或MB为单位的,所以特殊就特殊在发送的文件尺寸通常比较大,所以上传的文件内容会用multipart/form-data格式进行编码,然后再上传。urllib3对文件上传支持的非常好。只需要像设置普通的HTTP请求头一样在request方法中使用fields关键字参数指定一个描述上传文件的HTTP请求头字段,然后再通过元组指定相关属性即可,例如,上传文件名,文件类型等。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK