Why am I getting this error? and this is what I call the streaming API.
import tweepy
import sys
creds = json.loads(open('credential.json').read())
tw_consumer_key = creds['tw_consumer_key']
tw_consumer_secret = creds['tw_consumer_secret']
tw_access_token = creds['tw_access_token']
tw_access_token_secret = creds['tw_access_token_secret']
try:
auth = tweepy.OAuthHandler(tw_consumer_key, tw_consumer_secret)
auth.set_access_token(tw_access_token, tw_access_token_secret)
api = tweepy.API(auth)
except Exception:
service = None
api = None
Q = "Better"
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
try:
print "%s\n%s\n%s\n%s\n\n" % (status.text,
status.author.screen_name,
status.created_at,
status.source,)
except Exception, e:
print >> sys.stderr, 'Encountered Exception:', e
pass
def on_error(self, status_code):
print >> sys.stderr, 'Encountered error with status code:', status_code
return True
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True
class LiveStream(webapp2.RequestHandler):
def get(self):
streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout=60)
self.response.out.write(streaming_api.filter(track=Q))
Probably the reason for GAE does not allow the socket, I'm not sure how to apply the query term to receive certain filtered stream tweets. My goal with this part of the code is to get the live broadcast with the assigned keywords. If there are alternative methods, please contact.
source
share