From 4253e368fcc422976c130b018eec898d4212fe8a Mon Sep 17 00:00:00 2001 From: j3rome Date: Mon, 28 Jun 2021 12:39:03 -0400 Subject: [PATCH] * Fix HTTP error handling --- main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 914b51f..ff03396 100644 --- a/main.py +++ b/main.py @@ -38,13 +38,12 @@ def get_pypi_history(package_name, ignore_release_candidat=True): """ try: resp = urlopen(f"https://pypi.org/pypi/{package_name}/json") - except: - print("[ERROR] Internet access is required to fetch package history from Pypi") - exit(1) - - if resp.code != 200: - print(f"[INFO] Couldn't find package '{package_name} on Pypi. Ignoring") - return None + except Exception as e: + if hasattr(e, 'getcode') and e.getcode() == 404: + return None + else: + print("[ERROR] Internet access is required to fetch package history from Pypi") + exit(1) resp = json.loads(resp.read())