oreilly-japan / deep-learning-from-scratch

『ゼロから作る Deep Learning』(O'Reilly Japan, 2016)
MIT License
3.99k stars 3.34k forks source link

ch3/mnist_show.pyがHTTPErrorとなる #55

Closed hone-git closed 3 years ago

hone-git commented 3 years ago

MNISTをダウンロード・表示させるプログラムである, ch3/mnist_show.pyを実行すると以下のエラーを吐きます.

urllib.error.HTTPError: HTTP Error 403: Forbidden

dataset/mnist.py内の関数_downloadを以下に変更することで解決しました.

def _download(file_name):
    file_path = dataset_dir + "/" + file_name

    if os.path.exists(file_path):
        return

    print("Downloading " + file_name + " ... ")
    headers = {
        "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0"
        }
    request = urllib.request.Request(url_base+file_name, headers=headers)
    response = urllib.request.urlopen(request).read()
    with open(file_path, mode='wb') as f:
        f.write(response)
    print("Done")

DL先のサイトhttp://yann.lecun.com/ へのアクセス権限がないことが原因のようです. 「ブラウザからのアクセスだよ」と伝えてあげる必要があります. 私の場合はヘッダーをFirefoxと偽装することで解決しました.

koki0702 commented 3 years ago

ありがとうございます。 コード修正しました。

https://github.com/oreilly-japan/deep-learning-from-scratch/commit/f549a1886b4c03a252ac7549311e29c1ed78a8a1