Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tweepy error response status code 400

Tags:

python

tweepy

I'm trying to write a simple twitter bot using python and tweepy. The code is as follows:

import tweepy
CONSUMER_KEY = 'xxxxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxxxx'
ACCESS_KEY = 'xxxxxxxxxxxxxxxxxxxxx'
ACCESS_SECRET = 'xxxxxxxxxxxxxxxxx'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

api.update_status('hi')

I get the following error:

TweepError: Twitter error response: status code = 400

I would like some info on how to avoid this error

like image 656
Hassan Salman Avatar asked Jan 24 '15 10:01

Hassan Salman


2 Answers

This may be a bug that emerged in the 3.2.0 release of Tweepy. See this issue opened on GitHub. In that issue, TylerGlaiel notes that api.update_status fails if called thus:

api.update_status('Test')

But works if called like so:

api.update_status(status='Test')

I have also found this works. I imagine a fix will be out before long.

like image 132
Shon Avatar answered Sep 27 '22 12:09

Shon


This sentence: api.update_status(status='Test') let you know if your API Key and Token is working well. So, if you see:

TweepError: Twitter error response: status code = 400

Possibly means that you need to regenerate your credentiales for any reason. Regenerate your API Key, API Secret Key and your Tokens and will work.

like image 28
Yudi Guzmán Avatar answered Sep 25 '22 12:09

Yudi Guzmán