Python interface Automation 19-requests-toolbelt processing Multipart/form-data

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.