我使用tweepy來傳輸一些tweet。這是我的程序:tweepy在幾個小時後停止
import tweepy
import json
consumer_key = "***"
consumer_secret = "***"
access_token_key="***"
access_token_secret="***"
auth1 = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth1.set_access_token(access_token_key, access_token_secret)
api = tweepy.API(auth1)
class StreamListener(tweepy.StreamListener):
def on_status(self, status):
try:
print status.text
except Exception, e:
print 'Encountered Exception Tweet:', e
pass
return True
def on_error(self, status_code):
print 'Encountered error with status code:' + repr(status_code)
return True
def on_data(self, data):
if 'in_reply_to_status_id' in data:
status = tweepy.Status.parse(self.api, json.loads(data))
if self.on_status(status) is False:
return True
elif 'delete' in data:
delete = json.loads(data)['delete']['status']
if self.on_delete(delete['id'], delete['user_id']) is False:
return True
elif 'limit' in data:
if self.on_limit(json.loads(data)['limit']['track']) is False:
return True
return True
def on_timeout(self):
print 'Timeout...'
return True
l = StreamListener()
streamer = tweepy.Stream(auth=auth1, listener=l, timeout=36000000)
setTerms = ['enbrel']
streamer.filter(follow=None,track = setTerms)
兩三個小時後,此過程停止。沒有信號錯誤,超時等。它只是沒有得到更多的鳴叫。我在哪裏做錯了?
你已經能夠重現這種行爲?這可能是你的網絡連接有問題,或者Twitter的API有問題。 –