You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行基于Tweepy Client API v2的Twitter机器人时遭遇401 Unauthorized错误

Tweepy调用get_users_following返回401 Unauthorized,但API密钥在其他代码中可用

我运行了以下代码,尝试获取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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 11:40:01