Skip to content

Instantly share code, notes, and snippets.

@victormurcia
Created September 5, 2022 04:25
Show Gist options
  • Select an option

  • Save victormurcia/fde61cce600282690e30b90efd4f5e35 to your computer and use it in GitHub Desktop.

Select an option

Save victormurcia/fde61cce600282690e30b90efd4f5e35 to your computer and use it in GitHub Desktop.
download a file from a URL, returns content of downloaded file
# download a file from a URL, returns content of downloaded file
def download_url(urlpath):
try:
# open a connection to the server
with urlopen(urlpath, timeout=3) as connection:
# read the contents of the url as bytes and return it
return connection.read()
except:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment