Created
January 21, 2022 08:51
-
-
Save mrpbennett/b3890ca370af49bb15fc1c077bb3abe3 to your computer and use it in GitHub Desktop.
Ideal way to use requests
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
import requests | |
url = '...' | |
try: | |
r = requests.get(url) | |
r.raise_for_status() | |
if r.status_code == requests.codes.ok: | |
# Do something... | |
except requests.exceptions.HTTPError as err: | |
raise SystemExit(err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment