Reputation: 7072
I need to retrieve data from a REST API.
In the Centos shell I can do:
curl -H "ID:1234" -H "Password:ABC" http://url.com/curl
I am trying to do this with Requests in Python.
On the quickstart page I see:
payload = {'ID': '1234' , 'Password' : 'ABC' }
requests.get("http://url.com/curl", params=payload)
However this doesn't work. It only returns the status 200, but no data.
Upvotes: 1
Views: 3913
Reputation: 31801
Open chrome devtools > Network panel > right-click on a request > Copy as curl.
Next, paste the curl command into the web form linked below (I have no affiliation with the site)
There is also a pip package for this: (not tested)
Upvotes: 0
Reputation: 4058
With the -H
handle for curl, you're setting header values.
In requests, you pass header data the same way you do with the params but you use a different keyword.
headers = {'ID': '1234' , 'Password' : 'ABC' }
requests.get("http://url.com/curl", headers=headers)
See Custom Headers from the requests doc
Upvotes: 9