Search code examples
pythonhttpshttp-authentication

How do I send authenticated https requests using Python?


What is the equivalent Python to the following curl command?

curl https://www.streak.com/api/v1/boxes/{Keyhere}/  -u passwordhere:

I tried this but I get 400 errors:

requests.get('https://www.streak.com/api/v1/boxes/{Key}/threads -u PASSWORD:', auth=HTTPBasicAuth('USER', 'pass'))

Solution

  • This type of authentication is very common and the requests documentation covers it.

    requests.get('https://www.streak.com/api/v1/boxes/{Key}/threads', auth=(YOUR_API_KEY, ''))
    

    You need to remove the -u PASSWORD: from your destination.

    An alternative is to use the streak_client package on PiPY or GitHub