Skip to content Skip to sidebar Skip to footer

How To Convert Curl Command To Requests

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

Solution 1:

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

Solution 2:

Open chrome devtools > Network panel > right-click on a request > Copy as curl.

copy as curl

Next, paste the curl command into the web form linked below

There is also a pip package for this:

Post a Comment for "How To Convert Curl Command To Requests"