SHARE
TWEET

Untitled

a guest Jun 17th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2.  
  3. for url in ['https://api.github.com', 'https://api.github.com/invalid']:
  4.     try:
  5.         response = requests.get(url)
  6.  
  7.         # If the response was successful, no Exception will be raised
  8.         response.raise_for_status()
  9.     except Exception as err:
  10.         print(f'Other error occurred: {err}')  # Python 3.6
  11.     else:
  12.         print('Success!')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top