首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python - Traceback (最近一次调用):...

python - Traceback (最近一次调用):...
EN

Stack Overflow用户
提问于 2016-10-24 04:58:07
回答 1查看 1.1K关注 0票数 0

我试着用Python和tweepy从Twitter上收集数据。

我的代码是:

代码语言:javascript
复制
import tweepy

consumer_key="..."
consumer_secret="..."
access_key = "..."
access_secret = "..."


class CustomStreamListener(tweepy.StreamListener):
    def on_status(self, status):
        print (status.text)

    def on_error(self, status_code):
        print >> sys.stderr, 'Encountered error with status code:', status_code
        return True # Don't kill the stream

    def on_timeout(self):
        print >> sys.stderr, 'Timeout...'
        return True # Don't kill the stream


auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(track=['capital'], async=True) 

在我的控制台中,python return:

代码语言:javascript
复制
RT @gucamo74: @rubenuria eso es muy difícil. El Sevilla no tiene el halo protector arbitral de los equipos de la capital y del Barcelona.
RT @TonySantanaZA: @woznyjs On Macro scale, we failed 2 create Corporate stability, 4 investing Companies. Hence Capital flight,2 other mor… "Pour ne pas se faire rouler"...... #Capital

所以这很好,但在发了几条推文后,他给我看了这条消息:

代码语言:javascript
复制
Exception in thread Thread-10:
Traceback (most recent call last):
  File "//anaconda/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "//anaconda/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "//anaconda/lib/python3.5/site-packages/tweepy/streaming.py", line 286, in _run
    raise
RuntimeError: No active exception to reraise

你知道为什么吗?我希望在我向他求婚之前,气氛不会停止。

EN

回答 1

Stack Overflow用户

发布于 2016-10-24 05:44:52

我在这篇文章中找到了解决方案:

Unraised exception using Tweepy and MySQL

通过在https://github.com/tweepy/tweepy/blob/master/tweepy/streaming.py上检查tweepy/streaming.py,似乎tweepy在处理异常的方式上有一个bug

代码语言:javascript
复制
if exception:
        # call a handler first so that the exception can be logged.
        self.listener.on_exception(exception)
        raise

raise应为raise exception

这是魔术,但它有效..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40207718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档