[英]Why does Tweepy with Python 3 not return any data at all from a stream?
Python 3.5.2, Tweepy 3.5.0, Windows 8.1 Python 3.5.2,Tweepy 3.5.0,Windows 8.1
I'm following a tutorial made by sentdex that shows how to stream data from Twitter using tweepy. 我正在跟踪senddex制作的教程,该教程显示了如何使用tweepy从Twitter流数据。 (His tutorial is in Python 2 but it is pretty easy to Python 3-ify it) (他的教程在Python 2中,但是使用Python 3对其进行修饰很容易)
However, when I run the script, it doesn't spit out any data. 但是,当我运行脚本时,它不会吐出任何数据。 It hangs until I get a 3-way IncompleteRead exception, or until I do Ctrl+C. 它挂起,直到我收到三向IncompleteRead异常,或者直到执行Ctrl + C为止。
Here is my Listener class code: 这是我的侦听器类代码:
class listener(StreamListener):
def on_date(self,data):
try:
print(data)
save = open('twitDB.csv', 'a')
save.write(data)
save.write('\n')
save.close()
return True
except BaseException as e:
print('failed on data,',str(e))
time.sleep(5)
def on_error(self,status):
print(status)
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken,asecret)
twitterStream = Stream(auth=auth, listener=listener())
twitterStream.filter(track=["car"])
As you can see, I have it set up to catch errors and print data out while saving it to a csv, but it doesn't really do anything, just hangs. 如您所见,我将其设置为捕获错误并在将数据保存到csv的同时打印出数据,但实际上并没有执行任何操作,只是挂起了。
Also, for track, I did try to use something less general but it still hanged. 另外,为了跟踪,我确实尝试使用了一些不太通用的东西,但是它仍然挂死了。
When KeyboardInterrupt is raised: 引发KeyboardInterrupt时:
Traceback (most recent call last):
File "C:\Program Files\Python35\lib\site-packages\requests\packages\urllib3\co
ntrib\pyopenssl.py", line 217, in recv_into
return self.connection.recv_into(*args, **kwargs)
File "C:\Program Files\Python35\lib\site-packages\OpenSSL\SSL.py", line 1352,
in recv_into
self._raise_ssl_error(self._ssl, result)
File "C:\Program Files\Python35\lib\site-packages\OpenSSL\SSL.py", line 1167,
in _raise_ssl_error
raise WantReadError()
OpenSSL.SSL.WantReadError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "twittertest.py", line 33, in <module>
twitterStream.filter(track=["car"])
File "C:\Program Files\Python35\lib\site-packages\tweepy\streaming.py", line 4
45, in filter
self._start(async)
File "C:\Program Files\Python35\lib\site-packages\tweepy\streaming.py", line 3
61, in _start
self._run()
File "C:\Program Files\Python35\lib\site-packages\tweepy\streaming.py", line 2
63, in _run
self._read_loop(resp)
File "C:\Program Files\Python35\lib\site-packages\tweepy\streaming.py", line 3
13, in _read_loop
line = buf.read_line().strip()
File "C:\Program Files\Python35\lib\site-packages\tweepy\streaming.py", line 1
79, in read_line
self._buffer += self._stream.read(self._chunk_size)
File "C:\Program Files\Python35\lib\site-packages\requests\packages\urllib3\re
sponse.py", line 310, in read
data = self._fp.read(amt)
File "C:\Program Files\Python35\lib\http\client.py", line 448, in read
n = self.readinto(b)
File "C:\Program Files\Python35\lib\http\client.py", line 478, in readinto
return self._readinto_chunked(b)
File "C:\Program Files\Python35\lib\http\client.py", line 573, in _readinto_ch
unked
chunk_left = self._get_chunk_left()
File "C:\Program Files\Python35\lib\http\client.py", line 541, in _get_chunk_l
eft
chunk_left = self._read_next_chunk_size()
File "C:\Program Files\Python35\lib\http\client.py", line 501, in _read_next_c
hunk_size
line = self.fp.readline(_MAXLINE + 1)
File "C:\Program Files\Python35\lib\socket.py", line 575, in readinto
return self._sock.recv_into(b)
File "C:\Program Files\Python35\lib\site-packages\requests\packages\urllib3\co
ntrib\pyopenssl.py", line 230, in recv_into
[self.socket], [], [], self.socket.gettimeout())
KeyboardInterrupt
It's my first time going with a social media API, so I apologize if I'm missing something obvious. 这是我第一次使用社交媒体API,因此如果我遗漏了一些明显的东西,我深表歉意。 Help would be appreciated, thanks. 帮助将不胜感激,谢谢。
def on_date(self,data):
这应该是
def on_data(self,data):
没关系,当我将on_status与status.text一起使用时,它确实有效,一定是我所缺少的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.