Home:ALL Converter>Python POST request does not take form data with no files

Python POST request does not take form data with no files

Ask Time:2017-08-08T20:39:19         Author:user2281204

Json Formatter

Before downvoting/marking as duplicate, please note:

I have already tried out this, this, this, this,this, this - basically almost all the methods I could find pointed out by the Requests documentation but do not seem to find any solution.

Problem:

I want to make a POST request with a set of headers and form data. There are no files to be uploaded. As per the request body in Postman, we set the parameters by selecting 'form-data' under the 'Body' section for the request. Here is the code I have:

headers = {'authorization': token_string,
           'content-type':'multipart/form-data; boundary=----WebKitFormBoundaryxxxxxXXXXX12345'} # I get 'unsupported application/x-www-form-url-encoded' error if I remove this line

body = {
    'foo1':'bar1',
    'foo2':'bar2',
    #... and other form data, NO FILE UPLOADED  
    }
#I have also tried the below approach
payload = dict()
payload['foo1']='bar1'
payload['foo2']='bar2'
page = ''
page = requests.post(url, proxies=proxies, headers=headers, 
json=body, files=json.dump(body)) # also tried data=body,data=payload,files={} when giving data values

Error

{"errorCode":404,"message":"Required String parameter 'foo1' is not 
present"}

EDIT: Adding a trace of the network console. I am defining it in the same way in the payload as mentioned on the request payload.

Network from dev-tools, I am defining it in the same way in the payload as mentioned

Author:user2281204,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45568636/python-post-request-does-not-take-form-data-with-no-files
yy