Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download protected files from S3 using urllib package, instead of requests (tutorial1/2) #26

Open
jjmcnelis opened this issue Dec 3, 2020 · 0 comments
Assignees

Comments

@jjmcnelis
Copy link
Member

jjmcnelis commented Dec 3, 2020

https://github.com/podaac/AGU-2020/tree/main/Part-II/01_sst_shpfile

When using the tutorial linked above, I had to use the urllib package for the data file download from S3.

Right now, I get a 401 Unauthorized here with requests.get method:

r = requests.get(modis_url)
with open('tutorial1_data_MODIS.nc', 'wb') as f:
    f.write(r.content)

That's using the requests library. If I use this instead it downloads with the authenticated session managed by urllib:

import shutil
with request.urlopen(modis_url) as response, open('tutorial2_data_MODIS.nc', 'wb') as out_file:
    print('Content Size:', response.headers['Content-length'])
    shutil.copyfileobj(response, out_file)
    print("Downloaded request to tutorial2_data_MODIS.nc")

The second download method works for me, but not the first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants