我有一个长期运行的Twitter刮取脚本,它偶尔挂起堆栈跟踪
"/usr/lib/python2.7/ssl.py", line 305: self._sslobj.do_handshake()我的问题是“为什么?”还有“我能做些什么来修复它?”
通常情况下,这种情况会持续一周左右才会发生。最后一次,在处理tweepy挂起的4个线程中,有3个线程(第四个线程正在等待来自一个挂线程的信息)。奇怪的是,线程之间有相当长的延迟:首先,调用api.followers_ids()的线程挂起,大约12分钟后调用api.friends_ids()的线程挂起,然后1小时12分钟后(!)调用api.search()的线程挂起。在所有这些之间都有许多api调用。
在发送QUIT信号时,我有一小部分代码可以转储它的堆栈跟踪,对于挂起的线程,我得到了类似下面的内容。它们都来自(并包括)第二个条目( tweepy/binder.py, line 185, in _call部分)。另外两个人是从tweepy/cursor.py, line 85 in next和tweepy/cursor.py, line 60, in next来的
File "myTwitterScrapingScript.py", line 245, in checkStatus
status = api.rate_limit_status()
File "/scratch/bin/python-virtual-environments/tweepy-2/local/lib/python2.7/site-packages/tweepy/binder.py", line 185, in _call
return method.execute()
File "/scratch/bin/python-virtual-environments/tweepy-2/local/lib/python2.7/site-packages/tweepy/binder.py", line 146, in execute
conn.request(self.method, url, headers=self.headers, body=self.post_data)
File "/usr/lib/python2.7/httplib.py", line 958, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/httplib.py", line 992, in _send_request
self.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
self.send(msg) File "/scratch/bin/python-virtual-environments/tweepy-2/local/lib/python2.7/site-packages/tweepy/binder.py", line 185, in _call
return method.execute()
File "/scratch/bin/python-virtual-environments/tweepy-2/local/lib/python2.7/site-packages/tweepy/binder.py", line 146, in execute
conn.request(self.method, url, headers=self.headers, body=self.post_data)
File "/usr/lib/python2.7/httplib.py", line 958, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/httplib.py", line 992, in _send_request
self.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 776, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 1161, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
File "/usr/lib/python2.7/ssl.py", line 381, in wrap_socket
ciphers=ciphers)
File "/usr/lib/python2.7/ssl.py", line 143, in __init__
self.do_handshake()
File "/usr/lib/python2.7/ssl.py", line 305, in do_handshake
self._sslobj.do_handshake()在线程挂起的时间里,出现了一些令人讨厌的错误。这并不是很不寻常,尽管这个数字略高于正常水平。第四个看起来很有趣..。就在那根线挂掉之前。
[Errno 110] : Connection timed out大约7在上一次followers_ids()调用之前(其中有许多不同的api调用)。[Errno 104] Connection reset by peer大约3分钟后(再次,几次成功的呼叫之间)[Errno 110] Connection timed out大约在上一次friends_ids()电话之前1.5分钟。这是在api.search()线程中出现的,它在前三个挂起前大约5分钟就一直在等待,总共等待了大约15分钟。[Errno 104] Connection reset by peer大约比friends_ids()线程的最后消息早2毫秒,并且在同一个线程中。刚刚收集到的朋友ids页面看起来都很好,并且没有从这些调用中出错。[Errno 104] Connection reset by peer在search线程中,大约在friends_ids线程挂起后17分钟,在search线程挂起前近一小时。Failed to send request TweepError,大约1.5分钟后。Failed to send request's和[Errno 104] Connection reset by peer。search线程最终挂起之前,使用大量的search和lookup_users调用,大约15分钟是没有错误的。发布于 2013-10-09 23:34:49
问题似乎在于tweepy没有实现超时。在最近版本的tweepy中,这个问题已经解决了,这个问题从那以后就没有发生过了(在连续几个月的数据收集中)。
发布于 2019-08-05 16:02:34
请更新如下:
pip安装--升级证书
https://stackoverflow.com/questions/16183179
复制相似问题