Requests-toolbelt
1. Official document Address: Requests-toolbelt official documents
2. Installation of the environment
Pip Install Requests-toolbelt
Multipart/form-data Pass File
from requests_toolbelt import MultipartEncoderimport requestsm = 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})
Multipart/form-data form submission (non-file)
from requests_toolbelt import MultipartEncoderimport requestsm = MultipartEncoder( fields={'field0': 'value', 'field1': 'value'})r = requests.post('http://httpbin.org/post', data=m, headers={'Content-Type': m.content_type})
Duplicate multiple file parameters
1. When the parameters are repeated, the dictionary is not used and the list type
from requests_toolbelt import MultipartEncoderimport requestsm = MultipartEncoder( fields = [ ('source', ('f1.ext', f1, 'application/x-example-mimetype'), ('source', ('f2.ext', f2, 'application/x-example-mimetype'),] )r = requests.post('http://httpbin.org/post', data=m, headers={'Content-Type': m.content_type})
Python interface Automation 19-requests-toolbelt processing Multipart/form-data