urllib.error.HTTPError: HTTP Error 403: rate limit exceeded when loading resnet18 from pytorch hub
I am not sure why I get a rate limit error.
(fashcomp) [jalal@goku fashion-compatibility]$ python main.py --test --l2_embed --resume runs/nondisjoint_l2norm/model_best.pth.tar --datadir ../../../data/fashion
/scratch3/venv/fashcomp/lib/python3.8/site-packages/torchvision/transforms/transforms.py:310: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead.
  warnings.warn(&quot;The use of the transforms.Scale transform is deprecated, &quot; +
Traceback (most recent call last):
  File &quot;main.py&quot;, line 313, in &lt;module&gt;
    main()    
  File &quot;main.py&quot;, line 105, in main
    model = torch.hub.load('pytorch/vision:v1.9.0', 'resnet18', pretrained=True)
  File &quot;/scratch3/venv/fashcomp/lib/python3.8/site-packages/torch/hub.py&quot;, line 362, in load
    repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose)
  File &quot;/scratch3/venv/fashcomp/lib/python3.8/site-packages/torch/hub.py&quot;, line 162, in _get_cache_or_reload
    _validate_not_a_forked_repo(repo_owner, repo_name, branch)
  File &quot;/scratch3/venv/fashcomp/lib/python3.8/site-packages/torch/hub.py&quot;, line 124, in _validate_not_a_forked_repo
    with urlopen(url) as r:
  File &quot;/usr/local/lib/python3.8/urllib/request.py&quot;, line 222, in urlopen
    return opener.open(url, data, timeout)
  File &quot;/usr/local/lib/python3.8/urllib/request.py&quot;, line 531, in open
    response = meth(req, response)
  File &quot;/usr/local/lib/python3.8/urllib/request.py&quot;, line 640, in http_response
    response = self.parent.error(
  File &quot;/usr/local/lib/python3.8/urllib/request.py&quot;, line 569, in error
    return self._call_chain(*args)
  File &quot;/usr/local/lib/python3.8/urllib/request.py&quot;, line 502, in _call_chain
    result = func(*args)
  File &quot;/usr/local/lib/python3.8/urllib/request.py&quot;, line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: rate limit exceeded

I have:
$ pip freeze
h5py==3.3.0
joblib==1.0.1
numpy==1.21.2
Pillow==8.3.1
scikit-learn==0.24.2
scipy==1.7.1
sklearn==0.0
threadpoolctl==2.2.0
torch==1.9.0
torchaudio==0.9.0
torchvision==0.10.0
typing-extensions==3.10.0.0

and I followed this from https://pytorch.org/hub/pytorch_vision_resnet/ :


This is a bug in Pytorch 1.9. As a workaround, try adding:
torch.hub._validate_not_a_forked_repo=lambda a,b,c: True

to your script before any torch.hub call. i.e.:
torch.hub._validate_not_a_forked_repo=lambda a,b,c: True
model = torch.hub.load('pytorch/vision:v0.9.0', 'resnet18', pretrained=True)


According to Philip Meier(one of the developers)'s post , This is a bug introduced in Pytorch 1.9 (#56138) and you shouldn't be facing this in older versions.
This is already fixed in the master, but whether there is a 1.9.1 to have this shipped with is not known at the moment. So until 1.10 ships, you either have to use an older version or use torchvision instead or simply use the workaround proposed above.
Update:
Pytorch released a bugfix for 1.9 (i.e. 1.9.1) so updating to 1.9.1 should rectify this issue for good.
