1url = 'https://api.github.com/some/endpoint'
2headers = {'user-agent': 'my-app/0.0.1'}
3r = requests.get(url, headers=headers)
1Raise an exception if a request is unsuccessful
2
3import requests
4url = "http://mock.kite.com/status/404"
5r = requests.get(url)
6try:
7 r.raise_for_status()
8except requests.exceptions.HTTPError as e:
9 print e
10OUTPUT
11404 Client Error: NOT FOUND