I am trying to access the Twitter stream I worked with earlier when using Tweepy incorrectly. Now that I understand how Tweepy is meant to be used, I wrote the following Stream.py module. When I run it, I get an error code 401 that tells me that my auth was rejected. But before, I worked with the same token and secret. Any ideas?
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from tweepy import TweepError
from tweepy import error
consumer_key = "***"
consumer_secret = "***"
access_token="***"
access_token_secret="***"
class CustomListener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout."""
def on_status(self, status):
print status.text
return True
def on_error(self, status_code):
print "ERROR: ",; print status_code
return True
def on_timeout(self):
return True
def on_limit(self, track):
return True
def filter(self, track_list):
while True:
try:
self.stream.filter(track=track_list)
except error.TweepError as e:
raise TweepError(e)
def go(self):
listener = CustomListener()
auth = OAuthHandler(consumer_key, consumer_secret)
self.stream = Stream(auth,listener,timeout=3600)
listener.filter(['LOL'])
if __name__ == '__main__':
go(CustomListener)
source
share