Created
June 24, 2023 08:38
-
-
Save ocaoimh/af0757336e79cb85dc3432af2c3e17ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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