I'm trying to download these 2 files from that link but it keeps returning a 403 forbidden error, the website doesn't mention requiring any authentication to access files.
files = [
'sm/sm.data.1.AllData',
'ce/ce.data.0.AllCESSeries',
]
dir = os.path.abspath(os.path.dirname(__file__))
datadir = dir + "\\data"
os.chdir(datadir)
data_hostname = "http://download.bls.gov/pub/time.series/"
current_filesystem = datadir
def download_data():
for filename in files: # Loop through the files in files dictonary
filename_extension = filename[3:] + ".txt" # Filename munge
data_location = data_hostname + "" + filename # file name location
full_filepath = current_filesystem + "/" + filename_extension # full location
print("downloading from: " + data_location)
urllib.request.urlretrieve(data_location, full_filepath) # grab that shit
print("download path: " + full_filepath)
urllib.request.urlcleanup()
print("Finished Downloading Data")
Your code is missing a couple of required HTTP headers. Specifically, User-Agent and Accept-Language
Using requests (which you'll need to install if you don't already have it) you could do this: