Skip to content

Commit

Permalink
use httpbot as a wrapper to PY2/3 HTTPError()
Browse files Browse the repository at this point in the history
  • Loading branch information
MestreLion committed Feb 20, 2018
1 parent a341230 commit 242e8d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions httpbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions humblebundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 242e8d2

Please sign in to comment.