OAuth 1不使用HTTPX和Authlib
我目前正在使用request-oauthlib
库进行OAuth 1签名的请求。
from requests_oauthlib import OAuth1Session
self.session = OAuth1Session(
OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET,
oauth_token, oauth_token_secret,
signature_type='auth_header', realm='http://api.twitter.com'
)
self.session.headers = self.default_headers
self.session.verify = self.verify
self.session.proxies.update(self.proxies)
使用此,我可以成功地提出OAuth 1请求。但是我需要HTTP 2,并且想使用异步IO。这就是为什么我尝试切换到httpx
和authlib
。
from authlib.integrations.httpx_client import OAuth1Client
self.session = OAuth1Client(
OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET,
oauth_token, oauth_token_secret,
http2=True,
headers=self.default_headers,
proxies=self.proxies,
verify=self.context
)
self.session.auth.realm = 'http://api.twitter.com'
使用request-oauthlib
我可以毫无问题地提出签名请求。但是,当我尝试使用httpx
做同样的事情时,我会得到此响应:
{
"errors": [{
"code": 32,
"message": "Could not authenticate you."
}]
}
如果我使用网络调试器查看,我可以验证身份验证标头是否获得了所有正确的键HTTPX
。有人对如何解决此问题或如何正确调试这个问题有什么建议吗?提前致谢 :)
i am currently making oauth 1 signed requests using the requests-oauthlib
library.
from requests_oauthlib import OAuth1Session
self.session = OAuth1Session(
OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET,
oauth_token, oauth_token_secret,
signature_type='auth_header', realm='http://api.twitter.com'
)
self.session.headers = self.default_headers
self.session.verify = self.verify
self.session.proxies.update(self.proxies)
Using this i can successfully make oauth 1 requests. But I need http 2 and would like to use async io. Thats why i am trying to switch to httpx
and authlib
.
from authlib.integrations.httpx_client import OAuth1Client
self.session = OAuth1Client(
OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET,
oauth_token, oauth_token_secret,
http2=True,
headers=self.default_headers,
proxies=self.proxies,
verify=self.context
)
self.session.auth.realm = 'http://api.twitter.com'
With requests-oauthlib
i can make signed requests without a problem. But when i try to do the same with httpx
i get this response:
{
"errors": [{
"code": 32,
"message": "Could not authenticate you."
}]
}
If i take a look with a web debugger i can verify that the authentication header got all the right keys but somehow the request fails while using httpx
. Does anyone have any suggestions on how to resolve this issue or how to debug this properly? Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用类似的解决方案,您应该在使用HTTPX时导入Asyncoauth1client而不是OAuth1client。
I'm working on a similar solution, you should import AsyncOAuth1Client and not OAuth1Client when using httpx.