File tree 1 file changed +12
-4
lines changed
1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,17 @@ data_sources = {
72
72
** 2.** Load the data. First check if the data is stored locally; if not, then
73
73
download it.
74
74
75
+ ``` {code-cell} ipython3
76
+ :tags: [remove-cell]
77
+
78
+ # Use responsibly! When running notebooks locally, be sure to keep local
79
+ # copies of the datasets to prevent unnecessary server requests
80
+ headers = {
81
+ "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0"
82
+ }
83
+ request_opts = {"headers": headers}
84
+ ```
85
+
75
86
``` {code-cell} ipython3
76
87
import requests
77
88
import os
@@ -80,15 +91,12 @@ data_dir = "../_data"
80
91
os.makedirs(data_dir, exist_ok=True)
81
92
82
93
base_url = "http://yann.lecun.com/exdb/mnist/"
83
- headers = {
84
- "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0"
85
- }
86
94
87
95
for fname in data_sources.values():
88
96
fpath = os.path.join(data_dir, fname)
89
97
if not os.path.exists(fpath):
90
98
print("Downloading file: " + fname)
91
- resp = requests.get(base_url + fname, headers=headers, stream=True)
99
+ resp = requests.get(base_url + fname, stream=True, **request_opts )
92
100
with open(fpath, "wb") as fh:
93
101
for chunk in resp.iter_content(chunk_size=128):
94
102
fh.write(chunk)
You can’t perform that action at this time.
0 commit comments