Skip to content

add custom user agent for download_url #3498

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

Merged
merged 4 commits into from
Mar 3, 2021
Merged

Conversation

pmeier
Copy link
Collaborator

@pmeier pmeier commented Mar 3, 2021

Fixes #3497.

Comment on lines 21 to 24
def _urlretrieve(url: str, filename: str, **kwargs: Any) -> None:
request = urllib.request.Request(url, headers={"User-Agent": USER_AGENT})
with open(filename, "wb") as fh, urllib.request.urlopen(request) as response:
fh.write(response.read())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urllib.request.urlretrieve does not provide an option to set custom headers.

Comment on lines -86 to -87
import urllib

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urllib is part of the standard library so there is no reason to import it lazily.

@codecov
Copy link

codecov bot commented Mar 3, 2021

Codecov Report

Merging #3498 (e08ff9c) into master (89edfaa) will decrease coverage by 0.05%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3498      +/-   ##
==========================================
- Coverage   78.71%   78.65%   -0.06%     
==========================================
  Files         105      105              
  Lines        9711     9723      +12     
  Branches     1555     1557       +2     
==========================================
+ Hits         7644     7648       +4     
- Misses       1576     1583       +7     
- Partials      491      492       +1     
Impacted Files Coverage Δ
torchvision/datasets/utils.py 70.20% <93.33%> (-2.38%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89edfaa...e08ff9c. Read the comment docs.

pbar.update(chunk_size)
fh.write(chunk)


def gen_bar_updater() -> Callable[[int, int, int], None]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably remove / deprecate this now since we are not using it anymore.

Comment on lines -29 to +33
- name: Install PyTorch from the nightlies
run: |
pip install numpy
pip install --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
- name: Install torch nightly build
run: pip install --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html

- name: Install torchvision
run: pip install -e .
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a quick and dirty fix and should be revisited in a follow-up PR.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a ton for the speedy fix @pmeier!

Copy link

@codersguild codersguild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still throws the same error urllib.error.HTTPError: HTTP Error 403: Forbidden even after applying these changes to utils.py.

@pmeier pmeier deleted the user-agent branch March 5, 2021 17:45
facebook-github-bot pushed a commit that referenced this pull request Mar 10, 2021
Summary:
* add custom user agent for download_url

* fix progress bar

* lint

* [test] use repo instead of nightly for download tests

Reviewed By: NicolasHug, cpuhrsch

Differential Revision: D26945735

fbshipit-source-id: 6030e0927dda95afb63f32aceacfc3b479bf3f9f
@datumbox datumbox added bug and removed fix labels Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MNIST dataset no longer downloads (repeat of old fixed March 2020 problem)
7 participants