【发布时间】:2021-08-19 13:21:30
【问题描述】:
我已经使用常规的requests 模块成功实现了 OAuth1,如下所示:
import requests
from requests_oauthlib import OAuth1
oauth = OAuth1(client_key=oauth_cred["consumer_key"], client_secret=oauth_cred["consumer_secret"], resource_owner_key=oauth_cred["access_token"], resource_owner_secret=oauth_cred["access_token_secret"])
session = requests.Session()
session.auth = oauth
当尝试将其转移到aiohttp 时,我无法让它工作。用aiohttp.ClientSession() 代替requests.Session() 得到{'errors': [{'code': 215, 'message': 'Bad Authentication data.'}]}。
我在互联网上查看了一些解决方案,例如https://github.com/klen/aioauth-client,但这似乎是一种不同的方法。我只是希望它的功能与上面的示例完全相同。
我试过了
import aiohttp
from aioauth_client import TwitterClient
oauth = TwitterClient(consumer_key=oauth_cred["consumer_key"], consumer_secret=oauth_cred["consumer_secret"], oauth_token=oauth_cred["access_token"], oauth_token_secret=oauth_cred["access_token_secret"])
session = aiohttp.ClientSession()
session.auth = oauth
但我遇到了同样的错误。
我怎样才能让它工作?
【问题讨论】:
-
如果您正在寻找异步 OAuth 1.0 客户端,您可以尝试 HTTPX 版本的 Authlib:docs.authlib.org/en/latest/client/httpx.html#httpx-oauth-1-0
-
你能解决这个问题吗?我也遇到了同样的问题。
标签: python http asynchronous oauth aiohttp