amueller / introduction_to_ml_with_python

Notebooks and code for the book "Introduction to Machine Learning with Python"
7.44k stars 4.56k forks source link

got HTTPError: HTTP Error 403: Forbidden when execute fetch_lfw_people #167

Closed Lay4U93 closed 1 year ago

Lay4U93 commented 1 year ago

Hi

I study with book and got error when execute fetch_lfw_people

below is my code in chapter 3 for get face image


from sklearn.datasets import fetch_lfw_people
people = fetch_lfw_people(min_faces_per_person=20, resize=0.7)
image_shape = people.images[0].shape

fig, axes = plt.subplots(2, 5, figsize=(15, 8),
                         subplot_kw={'xticks': (), 'yticks': ()})
for target, image, ax in zip(people.target, people.images, axes.ravel()):
    ax.imshow(image)
    ax.set_title(people.target_names[target])

and I have error like below

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
Cell In [54], line 2
      1 from sklearn.datasets import fetch_lfw_people
----> 2 people = fetch_lfw_people(min_faces_per_person=20, resize=0.7)
      3 image_shape = people.images[0].shape
      5 fig, axes = plt.subplots(2, 5, figsize=(15, 8),
      6                          subplot_kw={'xticks': (), 'yticks': ()})

File D:\python\libraryml\venv\lib\site-packages\sklearn\datasets\_lfw.py:321, in fetch_lfw_people(data_home, funneled, resize, min_faces_per_person, color, slice_, download_if_missing, return_X_y)
    232 def fetch_lfw_people(
    233     *,
    234     data_home=None,
   (...)
    241     return_X_y=False,
    242 ):
    243     """Load the Labeled Faces in the Wild (LFW) people dataset \
    244 (classification).
    245 
   (...)
    319         .. versionadded:: 0.20
    320     """
--> 321     lfw_home, data_folder_path = _check_fetch_lfw(
    322         data_home=data_home, funneled=funneled, download_if_missing=download_if_missing
    323     )
    324     logger.debug("Loading LFW people faces from %s", lfw_home)
    326     # wrap the loader in a memoizing function that will return memmaped data
    327     # arrays for optimal memory usage

File D:\python\libraryml\venv\lib\site-packages\sklearn\datasets\_lfw.py:88, in _check_fetch_lfw(data_home, funneled, download_if_missing)
     86 if download_if_missing:
     87     logger.info("Downloading LFW metadata: %s", target.url)
---> 88     _fetch_remote(target, dirname=lfw_home)
     89 else:
     90     raise IOError("%s is missing" % target_filepath)

File D:\python\libraryml\venv\lib\site-packages\sklearn\datasets\_base.py:1511, in _fetch_remote(remote, dirname)
   1489 """Helper function to download a remote dataset into path
   1490 
   1491 Fetch a dataset pointed by remote's url, save into path using remote's
   (...)
   1507     Full path of the created file.
   1508 """
   1510 file_path = remote.filename if dirname is None else join(dirname, remote.filename)
-> 1511 urlretrieve(remote.url, file_path)
   1512 checksum = _sha256(file_path)
   1513 if remote.checksum != checksum:

File ~\AppData\Local\Programs\Python\Python39\lib\urllib\request.py:239, in urlretrieve(url, filename, reporthook, data)
    222 """
    223 Retrieve a URL into a temporary location on disk.
    224 
   (...)
    235 data file as well as the resulting HTTPMessage object.
    236 """
    237 url_type, path = _splittype(url)
--> 239 with contextlib.closing(urlopen(url, data)) as fp:
    240     headers = fp.info()
    242     # Just return the local path and the "headers" for file://
    243     # URLs. No sense in performing a copy unless requested.

File ~\AppData\Local\Programs\Python\Python39\lib\urllib\request.py:214, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    212 else:
    213     opener = _opener
--> 214 return opener.open(url, data, timeout)

File ~\AppData\Local\Programs\Python\Python39\lib\urllib\request.py:523, in OpenerDirector.open(self, fullurl, data, timeout)
    521 for processor in self.process_response.get(protocol, []):
    522     meth = getattr(processor, meth_name)
--> 523     response = meth(req, response)
    525 return response

File ~\AppData\Local\Programs\Python\Python39\lib\urllib\request.py:632, in HTTPErrorProcessor.http_response(self, request, response)
    629 # According to RFC 2616, "2xx" code indicates that the client's
    630 # request was successfully received, understood, and accepted.
    631 if not (200 <= code < 300):
--> 632     response = self.parent.error(
    633         'http', request, response, code, msg, hdrs)
    635 return response

File ~\AppData\Local\Programs\Python\Python39\lib\urllib\request.py:561, in OpenerDirector.error(self, proto, *args)
    559 if http_err:
    560     args = (dict, 'default', 'http_error_default') + orig_args
--> 561     return self._call_chain(*args)

File ~\AppData\Local\Programs\Python\Python39\lib\urllib\request.py:494, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
    492 for handler in handlers:
    493     func = getattr(handler, meth_name)
--> 494     result = func(*args)
    495     if result is not None:
    496         return result

File ~\AppData\Local\Programs\Python\Python39\lib\urllib\request.py:641, in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)
    640 def http_error_default(self, req, fp, code, msg, hdrs):
--> 641     raise HTTPError(req.full_url, code, msg, hdrs, fp)

HTTPError: HTTP Error 403: Forbidden

There was no problem when learning before. (About 3 years ago) But now, while studying again, I ran into this error.

Python evn is 3.9 and installed as pip install numpy scipy scikit-learn matplotlib pandas pillow graphviz

How can I solve this problem?

amueller commented 1 year ago

Does the problem persist?

Lay4U93 commented 1 year ago

no interest