python - Tweepy seems to be closing randomly -


i'm trying collect tweets using tweepy. using basic example program comes tweepy, modified write file. program runs 12 hours , one, seems randomly close no error message. here code:

from __future__ import absolute_import, print_function  tweepy.streaming import streamlistener tweepy import oauthhandler tweepy import stream   # go http://apps.twitter.com , create app. # consumer key , secret generated after consumer_key="" consumer_secret=""  # after step above, redirected app's page. # create access token under the "your access token" section access_token="" access_token_secret="" f = open('filename.txt', 'w') class stdoutlistener(streamlistener):     """ listener handles tweets received stream.     basic listener prints received tweets stdout.      """     def on_data(self, data):         print(data)         f.write(data)         return true      def on_error(self, status):         print(status)  if __name__ == '__main__':     l = stdoutlistener()     auth = oauthhandler(consumer_key, consumer_secret)     auth.set_access_token(access_token, access_token_secret)      stream = stream(auth, l)     stream.filter(track=['keyword']) 

thanks.

use try, except block , stream error print stdout. can catch error in except block , restart script, or log error.

try:      stream.filter(track=['keyword']) except exception, e:     print "error: %s" % str(e)     # log error or restart script 

my guess why it's crashing due similar, common error:

unicodedecodeerror: 'ascii' codec can't decode byte 0xe7 in position 4: ordinal not in range(128) 

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -