TweepError:错误的身份验证数据

时间:2019-08-27 10:54:07

标签: python web-scraping beautifulsoup tweepy

因此,我目前正在开发一个创建Twitter机器人的项目,尝试在cmd中运行以下命令时遇到了问题:

api.mentions_timeline()

当我在Python shell中键入API时,它将返回<tweepy.api.API object at 0x0000015A0345A348>,这是预期的结果。

我只创建了一个包含所有twitter api / tweepy键的文件:

import tweepy
ACCESS_TOKEN = "########"
ACCESS_TOKEN_SECRET = "############"
CONSUMER_KEY = "#################"
CONSUMER_SECRET = "################"

# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# Creation of the actual interface, using authentication
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
# collect tweets on     #MRT
for tweet in tweepy.Cursor(api.search,q="MRT",count=100,
                       lang="en",rpp=100).items():
    print (tweet.created_at, tweet.text)

运行api.mentions_timeline()会返回以下错误消息:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37\lib\site-packages\tweepy\binder.py", line 250, in _call
    return method.execute()
  File "C:\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': 215, 'message': 'Bad Authentication data.'}]
>>>

预期结果应该返回一些数据。

1 个答案:

答案 0 :(得分:1)

Tweepy无法对您进行身份验证。尝试用您的唯一代码再次填写密钥和秘密。这就是我能够解决的方式。

相关问题