when I use urllib2 and sometimes get an error like "urllib2 urlopen error [Errno 61] Connection refused", I will try to connect again. However, once the connection gets error, it will never succeed until I restart the python script. The following code is connection part.
req = urllib2.Request(self.__servAddr, body)
response = None
try:
response = urllib2.urlopen(req, timeout = 15)
res = response.read()
res = eval(res)
print res
if 200 == res["retcode"]:
if res["data"]:
infoReady = 1
xxxxxx
except Exception, e:
print "request error %s" % str(e)
if response:
response.close()
It semems the current connection has an effct on the next connection. How can I fix?