Error 401 and API V1.1 Python



I am trying to download the people that is twitting certain words in an area by this python code:

import sys
import tweepy


auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)

class CustomStreamListener(tweepy.StreamListener):
    def on_status(self, status):
        if 'busco casa' in status.text.lower():
            print (status.text)

    def on_error(self, status_code):
        print (sys.stderr, 'Encountered error with status code:', status_code)
        return True # Don't kill the stream

    def on_timeout(self):
        print (sys.stderr, 'Timeout...')
        return True # Don't kill the stream

sapi = tweepy.streaming.Stream(auth, CustomStreamListener())    

I am getting this error:
<ipykernel.iostream.OutStream object at 0x000001F4741034A8> Encountered error with status code: 401

I read in this link that the error is caused by:
Authentication credentials were missing or incorrect.
Also returned in other circumstances, for example all calls to API v1 endpoints now return 401 (use API v1.1 instead).

The authentication is there with updated keys. How should I use API v1.1?


If it’s an older version of tweepy you’ll need to update it - with pip install tweepy or from

I’m not sure, but I think the python API changed a little bit - Try running the streaming example is here: