Skip to content

Downloading 20_newsgroups results in 403 error #33002

Closed as duplicate
Closed as duplicate

Description

@lucasrct

Describe the bug

When trying to download the 20_newsgroups, I'm getting the following error:

File [~/miniconda3/lib/python3.13/urllib/request.py:613](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/urllib/request.py#line=612), in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)
    612 def http_error_default(self, req, fp, code, msg, hdrs):
--> 613     raise HTTPError(req.full_url, code, msg, hdrs, fp)

HTTPError: HTTP Error 403: Forbidden

Steps/Code to Reproduce

Steps to reproduce (if you ever downloaded this dataset, delete it from ~/scikit-learn or change the data_home parameter to point to another path):

from sklearn.datasets import fetch_20newsgroups

# Load the 20 Newsgroups dataset
newsgroups_train = fetch_20newsgroups()

Expected Results

Dataset should be downloaded and loaded in memory.

Actual Results

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
Cell In[2], line 4
      1 from sklearn.datasets import fetch_20newsgroups
      3 # Load the 20 Newsgroups dataset
----> 4 newsgroups_train = fetch_20newsgroups()

File [~/miniconda3/lib/python3.13/site-packages/sklearn/utils/_param_validation.py:218](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/site-packages/sklearn/utils/_param_validation.py#line=217), in validate_params.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    212 try:
    213     with config_context(
    214         skip_parameter_validation=(
    215             prefer_skip_nested_validation or global_skip_validation
    216         )
    217     ):
--> 218         return func(*args, **kwargs)
    219 except InvalidParameterError as e:
    220     # When the function is just a wrapper around an estimator, we allow
    221     # the function to delegate validation to the estimator, but we replace
    222     # the name of the estimator by the name of the function in the error
    223     # message to avoid confusion.
    224     msg = re.sub(
    225         r"parameter of \w+ must be",
    226         f"parameter of {func.__qualname__} must be",
    227         str(e),
    228     )

File [~/miniconda3/lib/python3.13/site-packages/sklearn/datasets/_twenty_newsgroups.py:320](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/site-packages/sklearn/datasets/_twenty_newsgroups.py#line=319), in fetch_20newsgroups(data_home, subset, categories, shuffle, random_state, remove, download_if_missing, return_X_y, n_retries, delay)
    318 if download_if_missing:
    319     logger.info("Downloading 20news dataset. This may take a few minutes.")
--> 320     cache = _download_20newsgroups(
    321         target_dir=twenty_home,
    322         cache_path=cache_path,
    323         n_retries=n_retries,
    324         delay=delay,
    325     )
    326 else:
    327     raise OSError("20Newsgroups dataset not found")

File [~/miniconda3/lib/python3.13/site-packages/sklearn/datasets/_twenty_newsgroups.py:79](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/site-packages/sklearn/datasets/_twenty_newsgroups.py#line=78), in _download_20newsgroups(target_dir, cache_path, n_retries, delay)
     76 os.makedirs(target_dir, exist_ok=True)
     78 logger.info("Downloading dataset from %s (14 MB)", ARCHIVE.url)
---> 79 archive_path = _fetch_remote(
     80     ARCHIVE, dirname=target_dir, n_retries=n_retries, delay=delay
     81 )
     83 logger.debug("Decompressing %s", archive_path)
     84 with tarfile.open(archive_path, "r:gz") as fp:

File [~/miniconda3/lib/python3.13/site-packages/sklearn/datasets/_base.py:1513](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/site-packages/sklearn/datasets/_base.py#line=1512), in _fetch_remote(remote, dirname, n_retries, delay)
   1511 while True:
   1512     try:
-> 1513         urlretrieve(remote.url, temp_file_path)
   1514         break
   1515     except (URLError, TimeoutError):

File [~/miniconda3/lib/python3.13/urllib/request.py:214](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/urllib/request.py#line=213), in urlretrieve(url, filename, reporthook, data)
    197 """
    198 Retrieve a URL into a temporary location on disk.
    199 
   (...)    210 data file as well as the resulting HTTPMessage object.
    211 """
    212 url_type, path = _splittype(url)
--> 214 with contextlib.closing(urlopen(url, data)) as fp:
    215     headers = fp.info()
    217     # Just return the local path and the "headers" for file://
    218     # URLs. No sense in performing a copy unless requested.

File [~/miniconda3/lib/python3.13/urllib/request.py:189](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/urllib/request.py#line=188), in urlopen(url, data, timeout, context)
    187 else:
    188     opener = _opener
--> 189 return opener.open(url, data, timeout)

File [~/miniconda3/lib/python3.13/urllib/request.py:495](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/urllib/request.py#line=494), in OpenerDirector.open(self, fullurl, data, timeout)
    493 for processor in self.process_response.get(protocol, []):
    494     meth = getattr(processor, meth_name)
--> 495     response = meth(req, response)
    497 return response

File [~/miniconda3/lib/python3.13/urllib/request.py:604](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/urllib/request.py#line=603), in HTTPErrorProcessor.http_response(self, request, response)
    601 # According to RFC 2616, "2xx" code indicates that the client's
    602 # request was successfully received, understood, and accepted.
    603 if not (200 <= code < 300):
--> 604     response = self.parent.error(
    605         'http', request, response, code, msg, hdrs)
    607 return response

File [~/miniconda3/lib/python3.13/urllib/request.py:533](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/urllib/request.py#line=532), in OpenerDirector.error(self, proto, *args)
    531 if http_err:
    532     args = (dict, 'default', 'http_error_default') + orig_args
--> 533     return self._call_chain(*args)

File [~/miniconda3/lib/python3.13/urllib/request.py:466](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/urllib/request.py#line=465), in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
    464 for handler in handlers:
    465     func = getattr(handler, meth_name)
--> 466     result = func(*args)
    467     if result is not None:
    468         return result

File [~/miniconda3/lib/python3.13/urllib/request.py:613](http://localhost:8888/lab/tree/miniconda3/lib/python3.13/urllib/request.py#line=612), in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)
    612 def http_error_default(self, req, fp, code, msg, hdrs):
--> 613     raise HTTPError(req.full_url, code, msg, hdrs, fp)

HTTPError: HTTP Error 403: Forbidden

Versions

System:
    python: 3.13.2 | packaged by Anaconda, Inc. | (main, Feb  6 2025, 18:56:02) [GCC 11.2.0]
executable: /home/lucas/miniconda3/bin/python
   machine: Linux-6.14.0-1018-oem-x86_64-with-glibc2.39

Python dependencies:
      sklearn: 1.8.0
          pip: 25.2
   setuptools: 80.9.0
        numpy: 2.2.6
        scipy: 1.16.3
       Cython: None
       pandas: 2.3.2
   matplotlib: 3.10.6
       joblib: 1.5.2
threadpoolctl: 3.6.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: /home/lucas/miniconda3/lib/python3.13/site-packages/numpy.libs/libscipy_openblas64_-56d6093b.so
        version: 0.3.29
threading_layer: pthreads
   architecture: SkylakeX

       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: /home/lucas/miniconda3/lib/python3.13/site-packages/scipy.libs/libscipy_openblas-b75cc656.so
        version: 0.3.29.dev
threading_layer: pthreads
   architecture: SkylakeX

       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libgomp
       filepath: /home/lucas/miniconda3/lib/python3.13/site-packages/scikit_learn.libs/libgomp-e985bcbb.so.1.0.0
        version: None

Activity

  1. added
    Needs Triage
    on Jan 5, 2026
  2. added a commit that references this issue on Jan 5, 2026
    13b7054
  3. allglc commented on Jan 5, 2026

    @allglc

    Same issue with fetch_california_housing.

  4. un1u3 commented on Jan 5, 2026

    @un1u3
    Contributor

    @lucasrct fixed this issue
    wait until maintainer merges the PR

  5. glemaitre commented on Jan 5, 2026

    @glemaitre
    Member

    Duplicate of #32961.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds Triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions