Skip to content

Instantly share code, notes, and snippets.

@alexanderankin
Created February 20, 2024 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderankin/42cbcfae0f7afe5730ee22c9e54c4db6 to your computer and use it in GitHub Desktop.
Save alexanderankin/42cbcfae0f7afe5730ee22c9e54c4db6 to your computer and use it in GitHub Desktop.
fetch.py
import urllib.request
def fetch(request: urllib.request.Request):
with urllib.request.urlopen(request) as response:
response_body = response.read().decode('utf-8')
if 200 < response.getcode() >= 400:
raise Exception(f"HTTP Error: {response.getcode()} - {response.reason}")
return response_body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment