Search code examples
python-2.7urltwittertweepy

Tweepy raises bad authentication data error


I am working on a twitter bot using tweepy. The bot auto-replies to specific users whose tweet handle it receives as input. The bot was working fine for weeks and then suddenly started throwing this 'Bad Authentication Data' or the following to be more precise :

tweepy.error.TweepError: [{'message': 'Bad Authentication data.', 'code': 215}]

Apparently the problem is in this particular part of the code :

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_key, access_secret)
    api = tweepy.API(auth)
    ts=api.user_timeline(screen_name=s,count=1)

I have entered the correct keys for the twitter application. I read about this problem on blogs where people say that it is an issue with POSTFIELDS and that it can be fixed by passing the status as URL in the api.update_status function. Is that right? If yes, please give me an example of how it can be done. I'm passing the message and tweet reply id in the update_status function. Thanks in advance.


Solution

  • I wrote

    auth.secure = True
    

    and it fixed in my case, hope it helps!