Skip to content

Commit 09a8945

Browse files
committed
header spoofing to circumvent 403.
1 parent 29902d7 commit 09a8945

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

content/tutorial-deep-learning-on-mnist.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,19 @@ filename = [["training_images", "train-images-idx3-ubyte.gz"], # 60,000 traini
7070
**2.** Download each of the 4 files in the list:
7171

7272
```{code-cell} ipython3
73-
from urllib import request
73+
import requests
7474
7575
base_url = "http://yann.lecun.com/exdb/mnist/"
76+
headers = {
77+
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0"
78+
}
7679
7780
for name in filename:
7881
print("Downloading file: " + name[1])
79-
request.urlretrieve(base_url + name[1], name[1])
82+
resp = requests.get(base_url + name[1], headers=headers, stream=True)
83+
with open(name[1], "wb") as fh:
84+
for chunk in resp.iter_content(chunk_size=128):
85+
fh.write(chunk)
8086
```
8187

8288
**3.** Decompress the 4 files and create 4 [`ndarrays`](https://numpy.org/doc/stable/reference/arrays.ndarray.html), saving them into a dictionary. Each original image is of size 28x28 and neural networks normally expect a 1D vector input; therefore, you also need to reshape the images by multiplying 28 by 28 (784).

0 commit comments

Comments
 (0)