【发布时间】: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 中完整命令的样子
>>> api <tweepy.api.API object at 0x0000015A0345A348> >>> 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.'}] >>> -
我还是不知道你是怎么调用这个脚本的。
标签: python web-scraping beautifulsoup tweepy