Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

401 Error when retrieving Twitter data using Tweepy

I am trying to retrieve Twitter data using Tweepy, using that below code, but I'm returning 401 error, and I regenerate the access and secret tokens, and the same error appeared.

#imports
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener

#setting up the keys
consumer_key = 'xxxxxxx'
consumer_secret = 'xxxxxxxx' 
access_token = 'xxxxxxxxxx'
access_secret = 'xxxxxxxxxxxxx'

class TweetListener(StreamListener):
# A listener handles tweets are the received from the stream.
#This is a basic listener that just prints received tweets to standard output

   def on_data(self, data):
       print (data)
       return True

   def on_error(self, status):
       print (status)



#printing all the tweets to the standard output
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)



stream = Stream(auth, TweetListener())

t = u"#سوريا"
stream.filter(track=[t])
like image 245
user3643380 Avatar asked Feb 09 '15 14:02

user3643380


1 Answers

Just reset your system's clock.

If an API request to authenticate comes from a server that claims it is a time that is outside of 15 minutes of Twitter time, it will fail with a 401 error.

ThankYou

like image 125
Prakhar Mishra Avatar answered Sep 21 '22 05:09

Prakhar Mishra