我使用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
您可以添加你的代碼? (最少如果可能的話) –
我已經添加了我的代碼 –