Created
September 23, 2019 23:58
-
-
Save iris9112/8ef47cec991915b80794994221938c8d 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
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