【问题标题】:TweepError : Bad Authentication dataTweepError:错误的身份验证数据
【发布时间】:2019-12-31 13:04:18
【问题描述】:

所以我目前正在开发一个创建 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.'}]
>>>

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

【问题讨论】:

  • 你如何尝试运行api.mentions_timeline()?这段代码 sn -p 只显示api.search
  • 这里是 cmd 中完整命令的样子 &gt;&gt;&gt; api &lt;tweepy.api.API object at 0x0000015A0345A348&gt; &gt;&gt;&gt; api.mentions_timeline() Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; 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.'}] &gt;&gt;&gt;
  • 我还是不知道你是怎么调用这个脚本的。

标签: python web-scraping beautifulsoup tweepy


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2012-12-10
    • 2018-10-30
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多