Skip to content

Instantly share code, notes, and snippets.

@iris9112
Created September 23, 2019 23:58
Show Gist options
  • Save iris9112/8ef47cec991915b80794994221938c8d to your computer and use it in GitHub Desktop.
Save iris9112/8ef47cec991915b80794994221938c8d to your computer and use it in GitHub Desktop.
import requests
from requests.exceptions import HTTPError
isa = 'https://api.github.com/users/iris9112/gists'
santi = 'https://api.github.com/users/rmotr-doesnt-exist/gists'
for url in [isa, santi]:
try:
response = requests.get(url)
# If the response was successful, no Exception will be raised
response.raise_for_status()
data = response.json()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # Python 3.6
except Exception as err:
print(f'Other error occurred: {err}') # Python 3.6
else:
print('Success!')
print(data[0]['url'])
print('--------')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment