Trong khi chạy chương trình này để lấy dữ liệu Twitter sử dụng Python 2.7.8:"IncompleteRead" Lỗi khi lấy Twitter dữ liệu sử dụng Python
#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])
sau khi chạy chương trình này trong vòng 5 giờ tôi đã nhận này Thông báo lỗi:
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)
>>>
Thực ra tôi không biết phải làm gì với vấn đề này !!!
https://github.com/tweepy/tweepy/pull/498 Điều này đã được khắc phục gần đây. Hãy chắc chắn rằng bạn đang sử dụng Tweepy – Luigi
mới nhất Cảm ơn bạn, tôi sẽ thử nó và tôi sẽ cập nhật trạng thái – Hana
thực sự khi tôi cài đặt "pip install tweepy" phiên bản mới của tweepy trong MAC OSX Terminal, tôi nhận thông báo này "Yêu cầu đã được đáp ứng (sử dụng --upgrade để nâng cấp): tweepy trong /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages Dọn dẹp ...", làm ơn làm thế nào tôi có thể ghi đè lên phiên bản trước? – Hana