Python requests library how to pass Authorization header with single token

I have a request URI and a token. If I use:

    curl -s "<MY_URI>" -H "Authorization: TOK:<MY_TOKEN>"

etc., I get a 200 and view the corresponding JSON data. So, I installed requests and when I attempt to access this resource I get a 403 probably because I do not know the correct syntax to pass that token. Can anyone help me figure it out? This is what I have:

    import sys,socket
    import requests

    r = requests.get('<MY_URI>','<MY_TOKEN>')
    r. status_code

I already tried:

    r = requests.get('<MY_URI>',auth=('<MY_TOKEN>'))
    r = requests.get('<MY_URI>',auth=('TOK','<MY_TOKEN>'))
    r = requests.get('<MY_URI>',headers=('Authorization: TOK:<MY_TOKEN>'))

But none of these work.

In python:


is equivalent to


And requests interprets

    ('TOK', '<MY_TOKEN>')

As you wanting requests to use Basic Authentication and craft an authorization header like so:


Which is the base64 representation of 'TOK:<MY_TOKEN>'

To pass your own header you pass in a dictionary like so:

    r = requests.get('<MY_URI>', headers={'Authorization': 'TOK:<MY_TOKEN>'})


Back to homepage or read more recommendations: