【发布时间】:2014-12-25 15:04:46
【问题描述】:
在运行此程序以使用 Python 2.7.8 检索 Twitter 数据时:
#imports
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
#setting up the keys
consumer_key = '…………...'
consumer_secret = '………...'
access_token = '…………...'
access_secret = '……………..'
class TweetListener(StreamListener):
# A listener handles tweets are the received from the stream.
#This is a basic listener that just prints received tweets to standard output
def on_data(self, data):
print (data)
return True
def on_error(self, status):
print (status)
#printing all the tweets to the standard output
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
stream = Stream(auth, TweetListener())
t = u"سوريا"
stream.filter(track=[t])
运行此程序 5 小时后,我收到以下错误消息:
Traceback (most recent call last):
File "/Users/Mona/Desktop/twitter.py", line 32, in <module>
stream.filter(track=[t])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/streaming.py", line 316, in filter
self._start(async)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/streaming.py", line 237, in _start
self._run()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/streaming.py", line 173, in _run
self._read_loop(resp)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/streaming.py", line 225, in _read_loop
next_status_obj = resp.read( int(delimited_string) )
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 543, in read
return self._read_chunked(amt)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 612, in _read_chunked
value.append(self._safe_read(chunk_left))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 660, in _safe_read
raise IncompleteRead(''.join(s), amt)
IncompleteRead: IncompleteRead(0 bytes read, 976 more expected)
>>>
其实这个问题我也不知道怎么办!!!
【问题讨论】:
-
github.com/tweepy/tweepy/pull/498 这是最近修复的。确保您使用的是最新的 Tweepy
-
谢谢,我试试,我会更新状态
-
实际上,当我在 MAC OSX 终端中安装“pip install tweepy”新版本的 tweepy 时,我收到此消息“要求已经满足(使用 --upgrade 升级):tweepy in / Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages 清理...”,请问如何覆盖以前的版本?
-
pip install tweepy --upgrade。该更新仅在 8 天前推送到 github,因此 pip 可能没有最新版本。您始终可以自己编辑源/检查以确保,我认为更改是〜一行。 -
aha 这与 tweepy2.3 相同,他只是在 tweepy/streaming.py 中添加了“除了(超时,ssl.SSLError,requests.compat.IncompleteRead)作为 exc:”这一行,实际上我已经在 tweepy2.3 有那行 :(
标签: python python-2.7 twitter tweepy