multipart/form-data Encoder
The main attraction is a streaming multipart form-data object, MultipartEncoder. Its API looks like this:
from requests_toolbelt import MultipartEncoder
import requests
m = MultipartEncoder(
fields={'field0': 'value', 'field1': 'value',
'field2': ('filename', open('file.py', 'rb'), 'text/plain')}
)
r = requests.post('http://httpbin.org/post', data=m,
headers={'Content-Type': m.content_type})
如果上传文件的时候,上传中文文件又问题,请更新
2.You can also use multipart/form-data encoding for requests that don’t require files:
from requests_toolbelt import MultipartEncoder
import requests
m = MultipartEncoder(fields={'field0': 'value', 'field1': 'value'})
r = requests.post('http://httpbin.org/post', data=m,
headers={'Content-Type': m.content_type})