Today I Learned
Ask or search…

Downloading files using python the correct way

Posted on 30 Aug, 2021
# determine the type of file over network
res = urllib.request.urlopen(url)
# get file content type (jpeg, pdf etc)
file_type =
# filename ofc
file_name =
# assuming file_name contains file extension as well
# otherwise use file_type and name together
urllib.request.urlretrieve(url, file_name)