【发布时间】:2017-10-13 09:00:04
【问题描述】:
我在我的树莓派上运行了一些推特机器人。我将大多数功能都包装在 try / 中,除了确保出现错误时它不会破坏程序并继续执行。
我还使用 Python 的 Streaming 库作为我希望机器人转发的标签的监控源。
尽管我将 main 函数包装在 try/except 中,但发生了一个导致程序终止的问题:
Unhandled exception in thread started by <function startBot5 at 0x762fbed0>
Traceback (most recent call last):
File "TwitButter.py", line 151, in startBot5
'<botnamehere>'
File "/home/pi/twitter/bots/TwitBot.py", line 49, in __init__
self.startFiltering(trackList)
File "/home/pi/twitter/bots/TwitBot.py", line 54, in startFiltering
self.myStream.filter(track=tList)
File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 445, in filter
self._start(async)
File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 361, in _start
self._run()
File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 294, in _run
raise exception
File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 263, in _run
self._read_loop(resp)
File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 313, in _read_loop
line = buf.read_line().strip()
AttributeError: 'NoneType' object has no attribute 'strip'
我的设置: 我有一个父类 TwitButter.py,它从 TwitBot.py 创建一个对象。这些对象是机器人,它们在自己的线程上启动,因此它们可以独立运行。
我在 TwitBot 中有一个运行 startFiltering() 函数的函数。它包含在 try/except 中,但我的 except 代码从未被触发。
我的猜测是流媒体库中发生了错误。可能该库编码不佳,并且在回溯底部指定的行上中断。
任何帮助都会很棒,我想知道其他人是否遇到过这个问题?
如果需要,我可以提供更多详细信息。
谢谢!!!
【问题讨论】:
-
固定在github #870 所以更新你的tweepy副本?
-
非常感谢!!!我已经进行了更改,所以应该一切正常!我很欣赏快速反应!而我是菜鸟,我不知道我可以修改这些库......
-
@gz 你想回答这个问题,所以我可以接受。它似乎正在工作。
标签: python twitter bots tweepy try-except