Skip to content

Instantly share code, notes, and snippets.

@swang373
Created October 24, 2019 15:56
Show Gist options
  • Save swang373/0887b2b7399e0e3a42a949dc988d8341 to your computer and use it in GitHub Desktop.
Save swang373/0887b2b7399e0e3a42a949dc988d8341 to your computer and use it in GitHub Desktop.
Example of URL fetching function using requests library
import requests
class HTTPRequestError(Exception):
pass
def fetch(url, params=None, **kwargs):
try:
response = requests.get(url, params, **kwargs)
if response.status_code == 200:
return response
else:
raise HTTPRequestError(f'The GET request to {url} responded with status code {response.status_code}')
except Exception:
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment