Python urllib2.URLError: <urlopen error [Errno 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次> [英] Python urllib2. URLError: <urlopen error [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted>
本文介绍了Python urllib2.URLError: <urlopen error [Errno 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在与 API 建立多个连接.进行删除查询.我在第 3000 次查询中遇到了该错误.
I'm making multiple connection to API. Making delete query. I got that error on a 3000'th query.
像这样:
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 个请求后,它说:
After about 3000'th request it says:
URLError: urlopen error [Errno 10048]
Only one usage of each socket address (protocol/network address/port)
is normally permitted
推荐答案
错误来自 Windows 本身,请参阅 避免 TCP/IP 端口耗尽.要修复关闭连接的错误,您没有调用 opener.close() 从而泄漏套接字.
The error comes from Windows itself, see Avoiding TCP/IP Port Exhaustion. To fix the error close your connection, you are not calling opener.close() hence leaking sockets.
这篇关于Python urllib2.URLError: <urlopen error [Errno 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文