【问题标题】:Tweepy streamer stopping after few secondsTweepy 流光在几秒钟后停止
【发布时间】:2016-08-16 01:25:40
【问题描述】:

嗨!

我遇到了一些关于 Python 的 tweepy 库的问题。我第一次启动以下脚本时,一切正常,第二次......脚本意外停止。

我没有发现任何有关此行为的信息,监听器在几秒钟后停止,并且我没有任何错误代码或其他东西。

有简单的代码:

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):
                try:
                        print 'n%s %s' % (status.author.screen_name, status.created_at)
                        json_data = status._json
                        #print json_data['text']

                        es.create(index="idx_twp",
                                doc_type="twitter_twp_nintendo",
                                body=json_data
                                )

                except Exception, e:
                        print e
                        pass

print('Starting Receiving')

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

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

streamer.filter(None,terms)
#streamer.userstream(None)

print ('Ending program')

然后是输出(只有 2 秒);

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

我正在使用 Python 2.7.5

有什么想法吗?

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

    嗨!

    我通过 virtualenv 将我的 Python 版本更改为 3.5,从而解决了这个奇怪的问题。目前,它运作良好。

    这可能是因为python版本,反正如果有人有这个,我只是建议使用virtualenv测试另一个python版本,看看会发生什么。

    仅供参考:我已经在 github 项目中打开了 issue #759

    【讨论】:

      猜你喜欢
      • 2018-10-22
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 2014-05-18
      • 2019-09-13
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多