Created
February 20, 2024 02:22
-
-
Save alexanderankin/42cbcfae0f7afe5730ee22c9e54c4db6 to your computer and use it in GitHub Desktop.
fetch.py
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 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