首页 > 解决方案 > 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 帖子。

标签: pythontwittertweepytraceback

解决方案


推荐阅读