Dipam7
Dipam7

Reputation: 63

HTTPError: HTTP Error 403: Forbidden on Google Colab

I am trying to download MNIST data in PyTorch using the following code:

train_loader = torch.utils.data.DataLoader(
      datasets.MNIST('data',
                      train=True,
                      download=True,
                      transform=transforms.Compose([
                         transforms.ToTensor(),
                         transforms.Normalize((0.1307,), (0.3081,))
                     ])),
      batch_size=128, shuffle=True)

and it gives the following error.

Downloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz to data/MNIST/raw/train-images-idx3-ubyte.gz
0it [00:00, ?it/s]
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-2-2fee284dabb8> in <module>()
      5                       transform=transforms.Compose([
      6                          transforms.ToTensor(),
----> 7                          transforms.Normalize((0.1307,), (0.3081,))
      8                      ])),
      9       batch_size=128, shuffle=True)

11 frames
/usr/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    648 class HTTPDefaultErrorHandler(BaseHandler):
    649     def http_error_default(self, req, fp, code, msg, hdrs):
--> 650         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    651 
    652 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 403: Forbidden

How do I solve this? The notebook was working before, I'm trying to rerun it but I got this error.

Upvotes: 6

Views: 8255

Answers (2)

matte
matte

Reputation: 97

My workaround is: run on your local machine a simple program to download the MNIST dataset from the torchvision.datasets module, save with pickle a copy on your machine and upload it in your Google Drive.

Is not proper fix but a viable and affordable workaround, hope it helps somehow

Upvotes: 0

jakevdp
jakevdp

Reputation: 86463

This is a new bug, reported here: https://github.com/pytorch/vision/issues/1938

See that thread for some potential workarounds until the issue is fixed in pytorch itself.

Upvotes: 6

Related Questions