Search code examples
python-3.xcurlpython-requestspycurl

Python equivalent of CURL with username and api token


I want to write the following curl command into python code. Following is the command for requesting some data from the URL.

<user_name> : replace with the username
<api_token> : replace with the token secret key

curl -u <user_name>/token:<api_token> <URL>

Solution

  • We can use requests module:

    response = requests.get(<URL>, auth = (f'{<user_name>}/token', <api_token>))