From 242e8d20ac148ab5f6ac150d1d63c2324c9e25d6 Mon Sep 17 00:00:00 2001 From: MestreLion Date: Tue, 20 Feb 2018 20:20:20 -0300 Subject: [PATCH] use httpbot as a wrapper to PY2/3 HTTPError() --- httpbot.py | 2 ++ humblebundle.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/httpbot.py b/httpbot.py index 097c4c1..48a1d23 100644 --- a/httpbot.py +++ b/httpbot.py @@ -27,9 +27,11 @@ if sys.version_info.major < 3: import urllib2 # @UnresolvedImport import urlparse # @UnresolvedImport + HTTPError = urllib2.HTTPError else: urllib2 = urllib.request # @UndefinedVariable urlparse = urllib.parse # @UndefinedVariable + HTTPError = urllib.error.HTTPError # @UndefinedVariable from lxml import html # Debian/Ubuntu: python-lxml diff --git a/humblebundle.py b/humblebundle.py index c4160c9..e0b9e58 100755 --- a/humblebundle.py +++ b/humblebundle.py @@ -145,7 +145,7 @@ def __init__(self, username=None, password=None, auth=None, code=None, 'qs' : "", '_le_csrf_token' : token, 'code': code.upper()}) - except httpbot.urllib2.HTTPError as e: + except httpbot.HTTPError as e: raise HumbleBundleError("Incorrect browser verification code") # "purchases" in the website. May be non-bundle like Store Purchases @@ -342,7 +342,7 @@ def download(self, name, path=None, bittorrent=False, game['human_name'], game['machine_name'], self._download_info(d))) try: return super(HumbleBundle, self).download(url, path, md5) - except httpbot.urllib2.HTTPError as e: + except httpbot.HTTPError as e: # Handle Unauthorized/Not Found (most likely outdated download URL) if not e.code in (403, 404): raise @@ -677,7 +677,7 @@ def save_cookies(res, force=False): if (current_url == requested_url or current_url not in self.auth_urls): return res - except httpbot.urllib2.HTTPError as e: + except httpbot.HTTPError as e: # Unauthorized (requires login) or something else? if not e.code == 401: raise @@ -713,7 +713,7 @@ def save_cookies(res, force=False): '_le_csrf_token': token}) save_cookies(res, force=True) - except httpbot.urllib2.HTTPError as e: + except httpbot.HTTPError as e: # 'Bad Request', 'Unauthorized' or 'Forbidden' are expected # in case of wrong passwords if e.code in [400, 401, 403]: