Revision: 3997
Author: btongminh
Date: 2007-08-07 20:12:41 +0000 (Tue, 07 Aug 2007)
Log Message:
-----------
Better exception handling.
Modified Paths:
--------------
trunk/pywikipedia/checkusage.py
Modified: trunk/pywikipedia/checkusage.py
===================================================================
--- trunk/pywikipedia/checkusage.py 2007-08-07 20:12:27 UTC (rev 3996)
+++ trunk/pywikipedia/checkusage.py 2007-08-07 20:12:41 UTC (rev 3997)
@@ -64,6 +64,7 @@
class HTTP(object):
def __init__(self, host):
+ self.host = host
self._conn = httplib.HTTPConnection(host)
#self._conn.set_debuglevel(100)
self._conn.connect()
@@ -105,10 +106,16 @@
else:
raise ValueError('Unknown api %s' % repr(api))
- res = self.request(method, query_string,
- {'Host': host, 'Content-Type':
'application/x-www-form-urlencoded'}, data)
- data = simplejson.load(res)
- res.close()
+ try:
+ res = self.request(method, query_string,
+ {'Host': host, 'Content-Type':
'application/x-www-form-urlencoded'}, data)
+ except httplib.ImproperConnectionState:
+ self._conn.close()
+ self.__init__(self.host)
+ try:
+ data = simplejson.load(res)
+ finally:
+ res.close()
return data
def close(self):
self._conn.close()
Show replies by date