简体   繁体   English

Python请求 - 验证令牌

[英]Python Requests - Auth Token

I am using Python Requests 2.7.0, and I am trying to pass a authtoken for a Session. 我正在使用Python Requests 2.7.0,我正在尝试为会话传递authtoken。 I am able to successfully connect using session.auth(user,pass) , but I am unfamiliar with how to pass a authtoken into a session. 我能够使用session.auth(user,pass)成功连接,但我不熟悉如何将authtoken传递给会话。

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. Authorization标头可能必须遵循特定模式,如您所联系的服务的文档中所述。 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> . 通常,该值必须以身份验证方案开始(如Basic和Digest身份验证方案 ,因此值将为<scheme> <token>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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