gpt4 book ai didi

python - 转推时 Tweepy 未经授权的 401 错误

转载 作者:行者123 更新时间:2023-12-01 23:12:29 25 4
gpt4 key购买 nike

我正在使用 Tweepy 构建一个 Twitter 机器人。当我测试它时,我尝试转推我所做的测试提及,但我收到未经授权的 401 错误。当获取时间线信息或只是打印提及 ID/内容时,一切都很好,但是当我尝试转发它时,它会引发 401:

我还更改了我的应用权限,以便在我第一次收到错误时写入和读取。

import tweepy

consumer_key = '##########'
consumer_secret = '#######'
acess_token = '##'
acess_token_secret = '#'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(acess_token, acess_token_secret)

api = tweepy.API(auth)

mentions = api.mentions_timeline()
for mention in mentions:
api.retweet(mention.id)
Traceback (most recent call last):
File "C:\Users\Lorenzo\desktop\twitter-bot\open-source-divulgator-bot\app.py", line 15, in <module>
api.retweet(mention.id)
File "C:\Users\Lorenzo\Desktop\twitter-bot\open-source-divulgator-bot\venv\lib\site-packages\tweepy\api.py", line 46, in wrapper
return method(*args, **kwargs)
File "C:\Users\Lorenzo\Desktop\twitter-bot\open-source-divulgator-bot\venv\lib\site-packages\tweepy\api.py", line 993, in retweet
return self.request(
File "C:\Users\Lorenzo\Desktop\twitter-bot\open-source-divulgator-bot\venv\lib\site-packages\tweepy\api.py", line 257, in request
raise Unauthorized(resp)
tweepy.errors.Unauthorized: 401 Unauthorized

最佳答案

按照@Harmon758 所说的,我能够运行代码,对我在 Twitter 开发者网站上的凭据进行简单的重新生成。

关于python - 转推时 Tweepy 未经授权的 401 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69563386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com