Error 401 and API V1.1 Python
Question: Good morning, I am trying to download the people that is twitting certain
words in an area by this python code:

    
    
    import sys
    import tweepy
    
    consumer_key="LMhbj3fywfKPNgjaPhOwQuFTY"
    consumer_secret="   LqMw9x9MTkYxc5oXKpfzvfbgF9vx3bleQHroih8wsMrIUX13nd"
    access_key="3128235413-OVL6wctnsx1SWMYAGa5vVZwDH5ul539w1kaQTyx"
    access_secret="fONdTRrD65ENIGK5m9ntpH48ixvyP2hfcJRqxJmdO78wC"
    
    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()) 
    sapi.filter(locations=[-78.37,-0.20,-78.48,-0.18])
    

I am getting this error: Encountered error with status code: 401

I read in this link <https://dev.twitter.com/overview/api/response-codes> 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?

Thanks, Anita


Answer: If it says that your credentials are incorrect, you might want to check your
credentials: you need to remove the whitespaces in your consumer secret for
your code to work.

Also, I just tested your credentials (without whitespaces) and they are
working. I can do whatever I want on behalf of your application. I suggest you
very quickly go to <https://apps.twitter.com> and generate new ones. Never
share your credentials. Especially online where everyone can see them.

