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


I'm unsure what is going wrong in here. The following code was working until 2 days ago. I'm using tweepy version number 3.6.0 on python3 in jupyter notebook. Now, when I execute the code given below, I keep getting the error, TweepError: [{'code': 215, 'message': 'Bad Authentication data.'}]. What am I doing wrong? I've already looked at similar posts <a href="https://stackoverflow.com/questions/20717945/tweepy-simple-script-with-bad-authentication-data-error" rel="nofollow">1</a>, <a href="https://stackoverflow.com/questions/13747870/getting-bad-authentication-data-error-from-twitter-api" rel="nofollow">2</a>,<a href="https://stackoverflow.com/questions/16426825/linq-to-twitter-authenticated-but-getting-215-bad-authentication-data" rel="nofollow">3</a>,<a href="https://stackoverflow.com/questions/29972426/twitter-error-code-215-bad-authentication-data" rel="nofollow">4</a>,<a href="https://stackoverflow.com/questions/17143985/twitter-api-error-215" rel="nofollow">5</a> and <a href="https://stackoverflow.com/questions/44864094/twitter-api-code215-messagebad-authentication-data" rel="nofollow">6</a> but no solution. Note, I have also regenerated the keys, still the error persists.

The code is;

import tweepy ckey = 'xxx' csecret = 'xxx' atoken = 'xxx' asecret = 'xxx' # OAuth process, using the keys and tokens auth = tweepy.OAuthHandler(ckey, csecret) auth.set_access_token(atoken, asecret) # Creation of the actual interface, using authentication api = tweepy.API(auth) # collect tweets on #MRT for tweet in tweepy.Cursor(api.search,q="MRT",count=100, lang="en",rpp=100, since="2017-04-03").items(): print (tweet.created_at, tweet.text)

On executing this code returns the following errors,

--------------------------------------------------------------------------- TweepError Traceback (most recent call last) <ipython-input-11-b3e4ffb2d94f> in <module>() 2 for tweet in tweepy.Cursor(api.search,q="MRT",count=100, 3 lang="en",rpp=100, ----> 4 since="2017-04-03").items(): 5 print (tweet.created_at, tweet.text) ~\Miniconda3\lib\site-packages\tweepy\cursor.py in __next__(self) 47 48 def __next__(self): ---> 49 return self.next() 50 51 def next(self): ~\Miniconda3\lib\site-packages\tweepy\cursor.py in next(self) 195 if self.current_page is None or self.page_index == len(self.current_page) - 1: 196 # Reached end of current page, get the next page... --> 197 self.current_page = self.page_iterator.next() 198 self.page_index = -1 199 self.page_index += 1 ~\Miniconda3\lib\site-packages\tweepy\cursor.py in next(self) 106 107 if self.index >= len(self.results) - 1: --> 108 data = self.method(max_id=self.max_id, parser=RawParser(), *self.args, **self.kargs) 109 110 if hasattr(self.method, '__self__'): ~\Miniconda3\lib\site-packages\tweepy\binder.py in _call(*args, **kwargs) 248 return method 249 else: --> 250 return method.execute() 251 252 # Set pagination mode ~\Miniconda3\lib\site-packages\tweepy\binder.py in execute(self) 232 raise RateLimitError(error_msg, resp) 233 else: --> 234 raise TweepError(error_msg, resp, api_code=api_error_code) 235 236 # Parse the response payload TweepError: Twitter error response: status code = 400

Any advice will be helpful.


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. <strong><em>These two parameters are important if you want to keep the tweets streaming on because the search API only gives you a <a href="http://docs.tweepy.org/en/v3.5.0/api.html" rel="nofollow">certain amount of tweets per request</a></em></strong>.

You have a <a href="https://developer.twitter.com/en/docs/basics/response-codes" rel="nofollow">TweepError with status code 400</a>. 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 <strong><em>beyond the rate limits of twitter</em></strong>.

Hopefully this helps.


  • Putting Twitter Widget's Javascript within tags, but have it rendered in
  • UnicodeEncodeError: 'cp949' codec can't encode character
  • Twitter atom don't retrieving old tweets
  • natural package for natural language facility not getting installed in meteor package
  • How to create instance variables explicitly?
  • Twitter API location of tweets
  • Get the hashtag using twitter gem
  • Mapbox title on markers always visible
  • Twitter like Model using SQL Server/Azure or Graph DB
  • Create sparse matrix from tweets
  • wordpress wpdb->update not working
  • Python 3.5.1 : NameError: name 'json' is not defined
  • Twitter API: Who unfollowed from me?
  • Exception AttributeError: “'NoneType' object has no attribute 'path'” in
  • get tweets with specific status ids using tweepy
  • Getting twitter account list in IOS-5 and user it with TWTweetComposeViewController
  • How to reply a tweet using the Twitter gem?
  • jQuery: replace() or wrap() http://name.tld/request_url?parameter with …?
  • Query timeout expired in django-mssql when executing custom SQL directly
  • Pre-populated SQLite Database not reading properly in Android Studio
  • Converting query results into DataFrame in python
  • Possible to get mouse events fired when cursor is outside page?
  • Using Sax parsing to edit and write XML in VB6
  • How to attach a node.js readable stream to a Sendgrid email?
  • Google Custom Search with transparent background
  • Django: Count of Group Elements
  • Insert into database using onclick function
  • Display issues when we change from one jquery mobile page to another in firefox
  • What is Eclipse's Declaration View used for?
  • Sending data from AppleScript to FileMaker records
  • MySQL WHERE-condition in procedure ignored
  • Can I make an Android app that runs a web view in Chrome 39?
  • Hazelcast - OperationTimeoutException
  • Do I've to free mysql result after storing it?
  • RestKit - RKRequestDelegate does not exist
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • Revoking OAuth Access Token Results in 404 Not Found
  • coudnt use logback because of log4j
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How do I use LINQ to get all the Items that have a particular SubItem?