Python requests library how to pass Authorization header with single token

后端 未结 8 1103
暗喜
暗喜 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:51

    You can also set headers for the entire session:

    TOKEN = 'abcd0123'
    HEADERS = {'Authorization': 'token {}'.format(TOKEN)}
    
    with requests.Session() as s:
    
        s.headers.update(HEADERS)
        resp = s.get('http://example.com/')
    

提交回复
热议问题