Python urllib2. URLError: <urlopen error [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted>

回眸只為那壹抹淺笑 提交于 2019-11-28 08:30:02

问题


I'm making multiple connection to API. Making delete query. I got that error on a 3000'th query.

Something like this:

 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)

Than in console:

for i in xrange(300000): 
    con.delete_request('/integration/sitemap/item.xml/media/%d/' % i)

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

回答1:


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.



来源:https://stackoverflow.com/questions/4526933/python-urllib2-urlerror-urlopen-error-errno-10048-only-one-usage-of-each-so

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!