Skip to content

Instantly share code, notes, and snippets.

@ocaoimh
Created June 24, 2023 08:38
Show Gist options
  • Save ocaoimh/af0757336e79cb85dc3432af2c3e17ab to your computer and use it in GitHub Desktop.
Save ocaoimh/af0757336e79cb85dc3432af2c3e17ab to your computer and use it in GitHub Desktop.
try:
request = requests.get('put your link here')
request.raise_for_status() # returns an HTTPError if the response is not OK
print("All good! Response code is", request.status_code)
except requests.exceptions.HTTPError as err:
if request.status_code == 404:
print("404: Oops, sorry we can't find that page!")
else:
print("The error code is", err.args[0]) # look up the 1st argument from HTTPError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment