Tweepy: tweepy.error.tweeperror 'code' 215 'message' 'bad authentication data.'

六月ゝ 毕业季﹏ 提交于 2019-12-07 23:17:25

I copied your code and executed it in my system and I was not able to find any errors. I'm using tweepy 3.6.0 and Python 3.5.2. There are two edits that I have done to your code.

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)

Notice the two parameters tweepy.API: wait_on_rate_limit and wait_on_rate_limit_notify. These two parameters are important if you want to keep the tweets streaming on because the search API only gives you a certain amount of tweets per request.

You have a TweepError with status code 400. According to the documentation, it says:

The request was invalid or cannot be otherwise served. An accompanying error message will explain further. Requests without authentication are considered invalid and will yield this response.

A Possible explanation is that the your twitter API keys do not authenticate anymore because you have been requesting beyond the rate limits of twitter.

Hopefully this helps.

I solved the problem using double quotes, I see that you used single quotes

CONSUMER_KEY = "xxx";

I had the same problem. Regenerating the Keys and tokens solved the problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!