Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "HTTP Error 403: Forbidden" error when download MNIST dataset

I use following code to get the MNIST dataset:

import torchvision.datasets
MNIST_train = torchvision.datasets.MNIST('./', download=True, train=True)

This code worked times ago, but now it shows the error:

Downloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz to ./MNIST\raw\train-images-idx3-ubyte.gz
HTTP Error 403: Forbidden
Stack trace:
 >  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\urllib\request.py", line 650, in http_error_default
 >    raise HTTPError(req.full_url, code, msg, hdrs, fp)
like image 491
Kola73 Avatar asked Nov 30 '22 13:11

Kola73


1 Answers

Using the suggestion mentioned here, adding this to the top of my script worked:

from six.moves import urllib    
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
like image 187
Rexcirus Avatar answered Dec 06 '22 20:12

Rexcirus