Python urllib2. URLError: <urlopen error [Errno 10048] Usually only one use of each socket address (protocol / network address / port)> is allowed
I am making several connections to the API. Fulfillment of request for removal. I got this error on the 3000th request.
Something like that:
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 the console:
for i in xrange(300000): con.delete_request('/integration/sitemap/item.xml/media/%d/' % i) After about the 3000th request, he says:
URLError: urlopen error [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted +4
1 answer
The error occurs from Windows itself, see Avoid TCP / IP Port Leaks . To fix the error, close your connection, you do not call openener.close (), therefore socket leakage.
+8