Python Requests Multipart HTTP POST

前端 未结 3 426
抹茶落季
抹茶落季 2021-01-03 05:32

I was wondering how do you translate something like this using Python Requests? In urllib2, you can manually manipulate the data that is being sent over the wire to the API

3条回答
  •  忘掉有多难
    2021-01-03 06:15

    I found out that in the python-requests library (v.0.13.3), your data will get wiped if you include the "data" field before the "files" field in the request call itself.

    For example,

    requests.post(url, headers=headers, data=data, files=files) 
    

    will yield empty form-data. However, the following will send the data dictionary as form-data

    requests.post(url, headers=headers, files=files, data=data)
    

    Thanks everyone for their answers

提交回复
热议问题