python - Tweepy 抛出回溯错误?
问题描述
所以我对 Python 比较陌生,一般来说对编程知之甚少。我一直在尝试编写一个愚蠢的 meme twitter 机器人,我和我的朋友们都认为它是个笑话。但我只是想看看我能不能让它运行起来。我当然不能。而且我无法理解如何仅根据文档和论坛帖子来处理回溯错误。
我在 Windows 上的 Pycharm 中运行 python 3.7,如果这有什么不同的话。将根据要求/需要更新详细信息。
到目前为止,我已经尝试过: - 删除其他 Java 解释器版本。- 使用 pip 卸载和重新安装 tweepy。-也许其他一些东西不太记得了,但这些是我尝试过的主要东西。
此处显示的代码:
import random
import tweepy
consumer_key = 'Insert Consumer Key'
consumer_secret = 'Insert Consumer Secret'
access_token = 'Access Token Goes Here'
access_token_secret = 'access token secret goes here'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
chance = random.randint(1, 1001)
def powder(num=chance / 100):
if num == 0.01:
api.update_status("*Special 0.01% chance tweet* I have a better monitor so I should be better at tekken.")
print("*Special 0.01% chance tweet* I have a better monitor so I should be better at tekken.")
elif num <= 27.3:
api.update_status("Hmmm. That's a lot of powder.")
print("Hmmm. That's a lot of powder.")
else:
api.update_status("Yes.")
print("Yes.")
powder()
抛出的错误如下所示:
C:\Users\colem\AppData\Local\Programs\Python\Python37\python.exe
C:/Users/colem/PycharmProjects/Playground/powder.py
Traceback (most recent call last):
File "C:/Users/colem/PycharmProjects/Playground/powder.py", line 29, in <module>
powder()
File "C:/Users/colem/PycharmProjects/Playground/powder.py", line 22, in powder
api.update_status("Hmmm. That's a lot of powder.")
File "C:\Users\colem\AppData\Local\Programs\Python\Python37\lib\site-packages\tweepy\api.py", line 194, in update_status
)(post_data=post_data, *args, **kwargs)
File "C:\Users\colem\AppData\Local\Programs\Python\Python37\lib\site-packages\tweepy\binder.py", line 250, in _call
return method.execute()
File "C:\Users\colem\AppData\Local\Programs\Python\Python37\lib\site-packages\tweepy\binder.py", line 234, in execute
raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{'code': 32, 'message': 'Could not authenticate you.'}]
Process finished with exit code 1
抱歉,如果这种格式很糟糕,我的第一篇 Stack Overflow 帖子。
解决方案
推荐阅读
- javascript - 使用 json 文件的路径时,Jquery.i18n 不起作用
- javascript - 每次在 Photoshop 中应用特定操作后都会提示“已完成”
- google-cloud-platform - GCP VM 上的 Fluentd 代理设置未将日志推送到日志资源管理器
- sql - 没有为 C1 的第 1 列指定任何列
- excel - 将数据和带有宏的按钮复制到另一个工作簿
- javascript - Lambda 不等待 Async/Await
- reactjs - 使用 axios react 将 json 数据发布到 API
- javascript - 我在使用 React 路由器时遇到问题,因为我的 url 在点击它时会得到更新,但页面没有被呈现
- r - R中的SOAP请求,带有WS-security,SOAPHandler
- sql - 我有一个查询,将输出作为开始日期和结束日期之间的年份和月份