raise a BrowserIncorrectPassword exception when handling a 401

This commit is contained in:
Romain Bignon 2012-07-22 21:12:51 +02:00
commit 8677d8b183

View file

@ -260,10 +260,14 @@ class StandardBrowser(mechanize.Browser):
return self._openurl(*args, **kwargs) return self._openurl(*args, **kwargs)
def get_exception(self, e): def get_exception(self, e):
if (isinstance(e, urllib2.HTTPError) and hasattr(e, 'getcode') and e.getcode() in (404, 403)) or \ if isinstance(e, urllib2.HTTPError) and hasattr(e, 'getcode'):
isinstance(e, mechanize.BrowserStateError): if e.getcode() in (404, 403):
return BrowserHTTPNotFound return BrowserHTTPNotFound
else: if e.getcode() == 401:
return BrowserIncorrectPassword
elif isinstance(e, mechanize.BrowserStateError):
return BrowserHTTPNotFound
return BrowserHTTPError return BrowserHTTPError
def readurl(self, url, *args, **kwargs): def readurl(self, url, *args, **kwargs):