使用requests的requests_toolbelt模块 ,需要自行安装。
http://www.lemfix.com/topics/44343
from requests_toolbelt import MultipartEncoder
import requests
m = MultipartEncoder(
fields={‘field0‘: ‘value‘,
‘field1‘: ‘value‘,
‘field2‘: (‘文件名称‘, open(‘文件地址/file.py‘, ‘rb‘), ‘text/plain‘)}
)
r = requests.post(‘http://httpbin.org/post‘,
data=m,
headers={‘Content-Type‘: m.content_type})