[Python] Python requests library how to pass Authorization header with single token

Discussão em 'Python' iniciado por Stack, Fevereiro 5, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página