Rakesh moorthy Rakesh moorthy - 4 years ago 179
Python Question

How to convert curl request to requests module in python

How to convert this curl request to python requests module compitable(Post request)

curl 'http://sss.com' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36' -H --data 'aq=%40syssource%3DProFind%20AND%20NOT%20%40title%3DCoveo%20AND%20NOT%20%40title%3Derror&searchHub=ProFind&xxx=yyy&xxx=yyy&xxx=yyy=10&xxx=yyy' --compressed


I am searching for requests module here

http://docs.python-requests.org/en/master/user/quickstart/


But they only have data value as key,value there

r = requests.post('http://httpbin.org/post', data = {'key':'value'})


So how could in convert the above curl post request to python requests module to make post request

Answer Source

The documentation you linked says:

There are many times that you want to send data that is not form-encoded. If you pass in a string instead of a dict, that data will be posted directly.

So just use

r = requests.post('http://sss.com', data = 'aq=%40syssource%3DProFind%20AND%20NOT%20%40title%3DCoveo%20AND%20NOT%20%40title%3Derror&searchHub=ProFind&xxx=yyy&xxx=yyy&xxx=yyy=10&xxx=yyy')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download