Tweepy streamer stopping after few seconds

python twitter tweepy

125 просмотра

1 ответ

591 Репутация автора

Hi !

I am experiencing some issue about tweepy library for Python. The first time I launched the below script, everything perfectly worked, and the second time... the script stop unexpectedly.

I did not found anything about this behavior, the Listener is stopping after few seconds, and I do not have any error code or something.

There is the simple code:

import tweepy
import sys
import json
from textwrap import TextWrapper
from datetime import datetime
from elasticsearch import Elasticsearch

consumer_key = "hidden"
consumer_secret = "hidden"
access_token = "hidden"
access_token_secret = "hidden"

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
ES_HOST = {"host" : "localhost", "port" : 9200}

es = Elasticsearch(hosts = [ES_HOST])

class StreamListener(tweepy.StreamListener):
        print('Starting StreamListener')
        status_wrapper = TextWrapper(width=60, initial_indent='    ', subsequent_indent='    ')

        def on_status(self, status):
                        print 'n%s %s' % (, status.created_at)
                        json_data = status._json
                        #print json_data['text']


                except Exception, e:
                        print e

print('Starting Receiving')

streamer = tweepy.Stream(auth=auth, listener=StreamListener(), timeout=3000000000)

#Fill with your own Keywords bellow
terms = ['nintendo']


print ('Ending program')

And then there is the ouput (only 2 seconds);

[root@localhost ~]# python projects/m/twitter/
Starting StreamListener
Starting Receiving
Ending program

I am using Python 2.7.5

Any ideas about ?

Автор: toshiro92 Источник Размещён: 18.07.2016 08:14

Ответы (1)

0 плюса

591 Репутация автора


Hi !

I solved this weird issue by changing my Python version to 3.5 via virtualenv. For now, it works well.

This could was due to the python version, anyway if someone have this, I just recommend to use virtualenv to test another Python version, and see what happens.

FYI : I already opened issue #759 into the github project.

Автор: toshiro92 Размещён: 15.08.2016 05:25
Вопросы из категории :