简体   繁体   中英

Python Requests - Auth Token

I am using Python Requests 2.7.0, and I am trying to pass a authtoken for a Session. I am able to successfully connect using session.auth(user,pass) , but I am unfamiliar with how to pass a authtoken into a session.

I tried using headers for the session, but this did not work. Here is the general flow of what I have:

session = requests.Session()
session.headers.update({'Authorization': TOKEN})
...

You are correctly setting a header to be used for all requests sent with the session.

You are probably not setting the header value correctly, however. The Authorization header probably has to follow a specific pattern, as outlined in the documentation for the service you are contacting. It is typical that the value must start with a authentication scheme (like the Basic and Digest authentication schemes , so the value would be <scheme> <token> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM