Python requests library how to pass Authorization header with single token

后端 未结 8 1111
暗喜
暗喜 2020-12-02 14:02

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

curl -s \"\" -H \"Authorization: TOK:\"

etc., I get a 200 and vie

8条回答
  •  孤城傲影
    2020-12-02 14:39

    In python:

    ('')
    

    is equivalent to

    ''
    

    And requests interprets

    ('TOK', '')
    

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

    'VE9LOjxNWV9UT0tFTj4K'
    

    Which is the base64 representation of 'TOK:'

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

    r = requests.get('', headers={'Authorization': 'TOK:'})
    

提交回复
热议问题