一小时后套接字超时

时间:2015-01-25 05:42:50

标签: python sockets ssl

所以我每60秒轮询一次数据,大约一小时后我就会收到这个错误。 不太确定这是什么或如何避免它。我知道我肯定是过度轮询,因为API faq说它每秒可以处理40个请求。

这是我正在使用的代码:

def httpPost(url,resource,params):
 headers = {
        "Content-type" : "application/x-www-form-urlencoded",
 }
 conn = http.client.HTTPSConnection(url, timeout=10)
 temp_params = urllib.parse.urlencode(params)
 conn.request("POST", resource, temp_params, headers)
 response = conn.getresponse()
 data = response.read().decode('utf-8')
 params.clear()
 conn.close()
 return data

回溯:

File "C:\Anaconda3\lib\http\client.py", line 1172, in getresponse response.begin()
File "C:\Anaconda3\lib\http\client.py", line 351, in begin version, status, reason = self._read_status()
File "C:\Anaconda3\lib\http\client.py", line 313, in _read_status
 line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Anaconda3\lib\socket.py", line 371, in readinto
 return self._sock.recv_into(b)
File "C:\Anaconda3\lib\ssl.py", line 746, in recv_into
return self.read(nbytes, buffer)
File "C:\Anaconda3\lib\ssl.py", line 618, in read
 v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

希望有人之前处理过这个问题,或者可以帮助我理解它。

我是否需要在代码中添加超时异常?

谢谢,

肖恩

0 个答案:

没有答案