使用tweepy
从Twitter Streaming API获取推文,我根据tweepy文档设置了一个监听器。它运行完美,有时持续数天,但不时出现此错误:
File "my_tweepy_script.py", line 90, in <module>
twitter_stream.filter(track=keywordlist, follow=userlist)
File "/usr/local/lib/python3.5/dist-packages/tweepy/streaming.py", line 445, in filter
self._start(async)
File "/usr/local/lib/python3.5/dist-packages/tweepy/streaming.py", line 361, in _start
self._run()
File "/usr/local/lib/python3.5/dist-packages/tweepy/streaming.py", line 294, in _run
raise exception
File "/usr/local/lib/python3.5/dist-packages/tweepy/streaming.py", line 263, in _run
self._read_loop(resp)
File "/usr/local/lib/python3.5/dist-packages/tweepy/streaming.py", line 313, in _read_loop
line = buf.read_line().strip()
AttributeError: 'NoneType' object has no attribute 'strip'
我想这意味着在Tweepy代码中某处有一个string.strip()
,并且在流式传输过程中发生了某些事情,导致存在一个NoneType
对象,其中应该有一个字符串。
如果没有流式脚本崩溃,有没有办法解决这些问题?