0

I had tried to fetch data from a website using python-requests using post method. But while am checking the Request payload it's showing as like below:

Content-Type: multipart/form-data; boundary=---------------------------7952717927472
Content-Length: 5372

-----------------------------7952717927472
Content-Disposition: form-data; name="id"

13529
-----------------------------7952717927472
Content-Disposition: form-data; name="num"


-----------------------------7952717927472
Content-Disposition: form-data; name="dowhat"

error
-----------------------------7952717927472
Content-Disposition: form-data; name="coupoun"

$ 2.00
-----------------------------7952717927472

I don't understand the format of the request payload and how this payload has to be passed along with requests.

response=requests.post(url, data = data)
Captureca
  • 61
  • 2
  • 8
  • try this. https://toolbelt.readthedocs.io/en/latest/user.html#multipart-form-data-encoder – arunp9294 Oct 13 '19 at 02:48
  • possible duplicate of https://stackoverflow.com/questions/33369306/parse-multipart-form-data-received-from-requests-post – arunp9294 Oct 13 '19 at 02:49

1 Answers1

0

Yes, I finally got it. Please see the below code using MultiparEncoder

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})

This works perfectly

Captureca
  • 61
  • 2
  • 8