运行基于Tweepy Client API v2的Twitter机器人时遭遇401 Unauthorized错误
我运行了以下代码,尝试获取ID为1550947094185349127的用户的关注列表:
import tweepy client = tweepy.Client( consumer_key=" CONSUMER KEY ", consumer_secret=" CONSUMER SECRET ", access_token=" ACCESS TOKEN ", access_token_secret=" ACCESS TOKEN SECRET " ) following = client.get_users_following(1550947094185349127) print(following)
得到的错误响应如下:
Traceback (most recent call last): File "C:\bot\Tests.py", line 11,
in
following = client.get_users_following(1550947094185349127)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\totes\AppData\Local\Programs\Python\Python311\Lib\site-packages\tweepy\client.py",
line 2147, in get_users_following
return self._make_request(
^^^^^^^^^^^^^^^^^^^ File "C:\Users\totes\AppData\Local\Programs\Python\Python311\Lib\site-packages\tweepy\client.py",
line 129, in _make_request
response = self.request(method, route, params=request_params,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File
"C:\Users\totes\AppData\Local\Programs\Python\Python311\Lib\site-packages\tweepy\client.py",
line 98, in request
raise Unauthorized(response) tweepy.errors.Unauthorized: 401 Unauthorized Unauthorized
我的API密钥是正确的,因为它们在另一段代码中可以正常使用。
内容的提问来源于stack exchange,提问作者Toma Schreibman

