Skip to content

Instantly share code, notes, and snippets.

@mrpbennett
Created January 21, 2022 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrpbennett/b3890ca370af49bb15fc1c077bb3abe3 to your computer and use it in GitHub Desktop.
Save mrpbennett/b3890ca370af49bb15fc1c077bb3abe3 to your computer and use it in GitHub Desktop.
Ideal way to use requests
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