FlorianREGAZ / Python-Tls-Client

Advanced HTTP Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add multipart/form-data

phgas opened this issue · comments

commented

with requests it's:

payload={'key_1': 'one','key_2': '2'}
response = requests.post(url, data=payload, files=[])

EDIT: possibility to change boundary in header/payload is recommended
see https://stackoverflow.com/questions/12385179/how-to-send-a-multipart-form-data-with-requests-in-python

commented

Semi-beautiful Solution:

from requests_toolbelt.multipart.encoder import MultipartEncoder


mp_encoder = MultipartEncoder(
    fields={
        'foo': 'bar'
    }
)

mp_encoder.to_string()
mp_encoder.content_type

Were you able to do it?

As @phgas already mentioned:
Check this #93

You need to submit
data = your_multipart_encoded_object.to_string().decode('utf-8')