我使用Tweepy库跟踪主题标签(我使用的是流API)和我在一定数量的记录后保存到硬盘驱动器上的文件中。我的代码工作,我离开它运行。过了一段时间,我随机得到以下错误流与Tweepy:随机获得“类型错误:不支持的操作数类型(S)为+:‘诠释’和‘海峡’
Exception in thread Thread-1:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/Library/Python/2.7/site-packages/tweepy/streaming.py", line 294, in _run
raise exception
TypeError: unsupported operand type(s) for +: 'int' and 'str'
如果我稍等一会,然后重新启动,程序开始运行,但我很快就再次出现错误。
我还注意到,到晚上下班回家时,会出现错误,即使重新启动,我也会继续收到错误,直到几小时后。
有没有人遇到过这个问题之前,如果是这样,什么是解决办法?
我运行的Python 2.7和3.5 Tweepy
感谢
更新:我的代码
trackList = '#GOP'
try:
listen = myListener.SListener(api)
stream = Stream(auth, listen)
stream.filter(track=trackList)
except Exception, inst:
print "An unexpected error occured"
print (type(inst))
_, _, tb = sys.exc_info()
filename, lineno, funname, line = traceback.extract_tb(tb)[-1]
print('{}:{}, in {}\n {}'.format(filename, lineno, funname, line))
而且在myListener.py
def on_status(self, status):
try:
self.output.write(status + "\n")
self.counter += 1
if self.counter >= 5000:
self.output.close()
self.output = open(time.strftime('%Y%m%d-%H%M%S') + '.json', 'w')
self.counter = 0
return
except Exception, inst:
print "An unexpected error occured in Listener"
print (type(inst))
_, _, tb = sys.exc_info()
filename, lineno, funname, line = traceback.extract_tb(tb)[-1]
print('{}:{}, in {}\n {}'.format(filename, lineno, funname, line))
pass
您可以添加你的代码? (最少如果可能的话) –
我已经添加了我的代码 –