我尝试用Python和tweepy从Twitter收集数据。在
我的代码是:
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返回:
^{pr2}$所以没关系,但在几条推特之后,他给了我这样一条信息:
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
你知道为什么吗?我希望在我问他之前不要停止。在
我在这篇文章中找到了解决方法:
Unraised exception using Tweepy and MySQL
通过检查tweepy/流媒体.py在https://github.com/tweepy/tweepy/blob/master/tweepy/streaming.py看来tweepy在处理异常的方式上有一个特别的bug
这个
raise
应该是raise exception
这很神奇,但它很管用。。。在
相关问题 更多 >
编程相关推荐