Twitter 机器人和 python 的 Tweepy 问题
Tweepy issues with twitter bot and python
我在我的 raspberryPi 上 运行 有几个推特机器人。我将大多数功能都包装在 try / 中,以确保如果出现错误,它不会破坏程序并继续执行。
我还使用 Python 的流媒体库作为我希望机器人转推的标签的监控来源。
尽管我将主要功能包装在 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'
我的设置:
我有一个父 class TwitButter.py,它从 TwitBot.py 创建一个对象。这些对象是机器人,它们在自己的线程上启动,因此它们可以 运行 独立。
我在 TwitBot 中有一个函数 运行 是 startFiltering() 函数。它被包裹在 try/except 中,但我的例外代码从未被触发。
我的猜测是错误发生在 Streaming 库中。也许该库编码不当,并在回溯底部指定的行上中断。
任何帮助都会很棒,我想知道其他人是否遇到过这个问题?
如果需要,我可以提供额外的细节。
谢谢!!!
这实际上是 github #870 在 2017-04 中修复的 tweepy 中的问题。所以,应该通过将本地副本更新到最新的主副本来解决。
我发现了什么:
- 通过网络搜索找到了 tweepy 源代码库。
- 在
streaming.py
中查看了最后一个回溯行的上下文。
- 注意到最近对文件的更改也是同样的问题。
我还会注意到,大多数情况下,您从 Python 库的深处获得回溯,问题来自错误调用它的代码,而不是库中的错误。但不总是。 :)
我在我的 raspberryPi 上 运行 有几个推特机器人。我将大多数功能都包装在 try / 中,以确保如果出现错误,它不会破坏程序并继续执行。
我还使用 Python 的流媒体库作为我希望机器人转推的标签的监控来源。
尽管我将主要功能包装在 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'
我的设置: 我有一个父 class TwitButter.py,它从 TwitBot.py 创建一个对象。这些对象是机器人,它们在自己的线程上启动,因此它们可以 运行 独立。
我在 TwitBot 中有一个函数 运行 是 startFiltering() 函数。它被包裹在 try/except 中,但我的例外代码从未被触发。
我的猜测是错误发生在 Streaming 库中。也许该库编码不当,并在回溯底部指定的行上中断。
任何帮助都会很棒,我想知道其他人是否遇到过这个问题?
如果需要,我可以提供额外的细节。
谢谢!!!
这实际上是 github #870 在 2017-04 中修复的 tweepy 中的问题。所以,应该通过将本地副本更新到最新的主副本来解决。
我发现了什么:
- 通过网络搜索找到了 tweepy 源代码库。
- 在
streaming.py
中查看了最后一个回溯行的上下文。 - 注意到最近对文件的更改也是同样的问题。
我还会注意到,大多数情况下,您从 Python 库的深处获得回溯,问题来自错误调用它的代码,而不是库中的错误。但不总是。 :)