我正在与API建立多个连接。进行删除查询。我在第3000个查询中遇到了该错误。
像这样:
def delete_request(self,path): opener = urllib2.build_opener(urllib2.HTTPHandler) request = urllib2.Request('%s%s'%(self.endpoint,path)) signature = self._gen_auth('DELETE', path, '') request.add_header('X-COMPANY-SIGNATURE-AUTH', signature) request.get_method = lambda: 'DELETE' resp = opener.open(request)
比在控制台中:
for i in xrange(300000): con.delete_request('/integration/sitemap/item.xml/media/%d/' % i)
在第3000个请求之后,它会说:
URLError: urlopen error [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
该错误来自Windows本身,请参阅避免TCP / IP端口耗尽。要修复错误,请关闭您的连接,因为您没有在调用opener.close()从而导致套接字泄漏。