* Fix HTTP error handling

This commit is contained in:
j3rome 2021-06-28 12:39:03 -04:00
parent f94c4a2d7c
commit 4253e368fc

13
main.py
View File

@ -38,13 +38,12 @@ def get_pypi_history(package_name, ignore_release_candidat=True):
""" """
try: try:
resp = urlopen(f"https://pypi.org/pypi/{package_name}/json") resp = urlopen(f"https://pypi.org/pypi/{package_name}/json")
except: except Exception as e:
print("[ERROR] Internet access is required to fetch package history from Pypi") if hasattr(e, 'getcode') and e.getcode() == 404:
exit(1) return None
else:
if resp.code != 200: print("[ERROR] Internet access is required to fetch package history from Pypi")
print(f"[INFO] Couldn't find package '{package_name} on Pypi. Ignoring") exit(1)
return None
resp = json.loads(resp.read()) resp = json.loads(resp.read())