Creating Post Request In Python, Need To Send Data As Multipart/form-data?
I'm in the process of writing a very simple Python application for a friend that will query a service and get some data in return. I can manage the GET requests easily enough, but
Solution 1:
Maybe you want to try the requests lib, You can pass a files
param, then requests will send a multipart/form-data POST instead of an application/x-www-form-urlencoded POST. You are not limited to using actual files in that dictionary, however:
import requests
response = requests.post('http://httpbin.org/post', files=dict(foo='bar'))
print response.status_code
If you want to know more about the requests lib, and specially in sending multipart forms take a look at this:
http://docs.python-requests.org/en/master/ and http://docs.python-requests.org/en/master/user/advanced/?highlight=Multipart-Encoded%20Files
Post a Comment for "Creating Post Request In Python, Need To Send Data As Multipart/form-data?"