因此,我对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帖子。