Skip to content

Getting HTTPError: HTTP Error 403: Forbidden when trying to load California Housing dataset #28297

Closed

Description

@AryamanBhatia

Describe the bug

When trying to load the dataset I get an error.

Steps/Code to Reproduce

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split 
from sklearn.preprocessing import StandardScaler

housing = fetch_california_housing()

X_train_full, X_test, y_train_full, y_test = train_test_split(
housing.data, housing.target)
X_train, X_valid, y_train, y_valid = train_test_split(X_train_full, y_train_full)

scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_valid_scaled = scaler.transform(X_valid)
X_test_scaled = scaler.transform(X_test)

Expected Results

Dataset loads

Actual Results

HTTPError                                 Traceback (most recent call last)
[/var/folders/wx/mz49j6yd5514yjn5k60sk6900000gn/T/ipykernel_16344/1379907178.py](https://file+.vscode-resource.vscode-cdn.net/var/folders/wx/mz49j6yd5514yjn5k60sk6900000gn/T/ipykernel_16344/1379907178.py) in <module>
      3 from sklearn.preprocessing import StandardScaler
      4 
----> 5 housing = fetch_california_housing()
      6 
      7 X_train_full, X_test, y_train_full, y_test = train_test_split(

[~/opt/anaconda3/lib/python3.9/site-packages/sklearn/datasets/_california_housing.py](https://file+.vscode-resource.vscode-cdn.net/Users/aryamanbhatia/neural%20network%20for%20practice/~/opt/anaconda3/lib/python3.9/site-packages/sklearn/datasets/_california_housing.py) in fetch_california_housing(data_home, download_if_missing, return_X_y, as_frame)
    133     This dataset consists of 20,640 samples and 9 features.
    134     """
--> 135     data_home = get_data_home(data_home=data_home)
    136     if not exists(data_home):
    137         makedirs(data_home)

[~/opt/anaconda3/lib/python3.9/site-packages/sklearn/datasets/_base.py](https://file+.vscode-resource.vscode-cdn.net/Users/aryamanbhatia/neural%20network%20for%20practice/~/opt/anaconda3/lib/python3.9/site-packages/sklearn/datasets/_base.py) in _fetch_remote(remote, dirname)

[~/opt/anaconda3/lib/python3.9/urllib/request.py](https://file+.vscode-resource.vscode-cdn.net/Users/aryamanbhatia/neural%20network%20for%20practice/~/opt/anaconda3/lib/python3.9/urllib/request.py) in urlretrieve(url, filename, reporthook, data)
    237     url_type, path = _splittype(url)
    238 
--> 239     with contextlib.closing(urlopen(url, data)) as fp:
    240         headers = fp.info()
    241 
...
--> 641         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    642 
    643 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 403: Forbidden

Versions

System:
    python: 3.9.13 (main, Aug 25 2022, 18:29:29)  [Clang 12.0.0 ]
executable: /Users/aryamanbhatia/opt/anaconda3/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
          pip: 22.2.2
   setuptools: 63.4.1
      sklearn: 1.0.2
        numpy: 1.26.3
        scipy: 1.9.1
       Cython: 0.29.32
       pandas: 1.4.4
   matplotlib: 3.5.2
       joblib: 1.1.0
threadpoolctl: 2.2.0

Built with OpenMP: True

Activity

  1. added
    Needs Triage
    on Jan 28, 2024
  2. glemaitre commented on Jan 28, 2024

    @glemaitre
    Member

    I cannot reproduce. Either it was something transient or it is on your network side.

  3. minkhantDoctoral commented on May 13, 2024

    @minkhantDoctoral

    I got the same error on Google Colab too. Someone said this bug occurs very frequent. Sometime it works, sometime it doesn't. Is there any solution to it?

  4. AsierMM commented on May 14, 2024

    @AsierMM

    I tried yo change the account and it worked. If you change the account that you are working with and try the same code it should be fine.

  5. tdtu98 commented on May 25, 2024

    @tdtu98

    Got the same error, don't know how to fix it.

  6. Diyago commented on May 25, 2024

    @Diyago

    same, seems no fix half year(

  7. Diyago commented on May 25, 2024

    @Diyago

    image

  8. lemeb commented on May 27, 2024

    @lemeb

    Same here! (Based in France FYI, but using Colab)

  9. mateors6 commented on Jun 7, 2024

    @mateors6

    I got the same problem in Spain, using Colab. But if I run it on Spyder it works fine!

  10. glemaitre commented on Jun 7, 2024

    @glemaitre
    Member

    I'm reopening this issue because we have too many reported issues.

  11. glemaitre commented on Jun 7, 2024

    @glemaitre
    Member

    I would propose to store the dataset directly on OpenML and call fetch_openml internally.

  12. lesteve commented on Jun 7, 2024

    @lesteve
    Member

    I was able to reproduce the HTTP 403 inside Colab. Note this is not only fetch_california_housing but all scikit-learn datasets on Figshare, so fetch_covtype, fetch_rcv1, etc ...

    ❯ git grep 'figshare'
    sklearn/datasets/_california_housing.py:    url="https://ndownloader.figshare.com/files/5976036",
    sklearn/datasets/_covtype.py:    url="https://ndownloader.figshare.com/files/5976039",
    sklearn/datasets/_kddcup99.py:    url="https://ndownloader.figshare.com/files/5976045",
    sklearn/datasets/_kddcup99.py:    url="https://ndownloader.figshare.com/files/5976042",
    sklearn/datasets/_lfw.py:    url="https://ndownloader.figshare.com/files/5976018",
    sklearn/datasets/_lfw.py:    url="https://ndownloader.figshare.com/files/5976015",
    sklearn/datasets/_lfw.py:        url="https://ndownloader.figshare.com/files/5976012",
    sklearn/datasets/_lfw.py:        url="https://ndownloader.figshare.com/files/5976009",
    sklearn/datasets/_lfw.py:        url="https://ndownloader.figshare.com/files/5976006",
    sklearn/datasets/_olivetti_faces.py:    url="https://ndownloader.figshare.com/files/5976027",
    sklearn/datasets/_rcv1.py:        url="https://ndownloader.figshare.com/files/5976069",
    sklearn/datasets/_rcv1.py:        url="https://ndownloader.figshare.com/files/5976066",
    sklearn/datasets/_rcv1.py:        url="https://ndownloader.figshare.com/files/5976063",
    sklearn/datasets/_rcv1.py:        url="https://ndownloader.figshare.com/files/5976060",
    sklearn/datasets/_rcv1.py:        url="https://ndownloader.figshare.com/files/5976057",
    sklearn/datasets/_rcv1.py:    url="https://ndownloader.figshare.com/files/5976048",
    sklearn/datasets/_species_distributions.py:    url="https://ndownloader.figshare.com/files/5976075",
    sklearn/datasets/_species_distributions.py:    url="https://ndownloader.figshare.com/files/5976078",
    sklearn/datasets/_twenty_newsgroups.py:    url="https://ndownloader.figshare.com/files/5975967"
    

    I am wondering if Figshare is not blocking some IP address, the HTTP 403 Forbidden is a bit unexpected ...

    Retrying a few times, it seems to be quite consistent, i.e. if you keep retrying the problem does not go away.

  13. 17 remaining items

  14. gigit0000 commented on Jun 16, 2024

    @gigit0000

    It's strange - the code runs perfectly on Colab but fails on Kaggle, at the same time even on the same local machine. Maybe this info can help troubleshoot the issue.

  15. Abdullah-R commented on Jun 17, 2024

    @Abdullah-R

    If you're experiencing this on Google Colab, the error seems to disappear if you switch to a TPU runtime (different servers hosting I guess?).

  16. lesteve commented on Jun 18, 2024

    @lesteve
    Member

    If you're experiencing this on Google Colab, the error seems to disappear if you switch to a TPU runtime (different servers hosting I guess?).

    I think this is a similar work-around as disconnecting the runtime mentioned in #28297 (comment) although a wild-guess could be that the TPU servers have less chance to be blocked (at least for now)?

  17. lesteve commented on Jun 18, 2024

    @lesteve
    Member

    It's strange - the code runs perfectly on Colab but fails on Kaggle, at the same time even on the same local machine. Maybe this info can help troubleshoot the issue.

    I tried on Kaggle notebooks and it seems like indeed the problem happens from time to time. The work-around is to click on the power button (Stop session), reexecute the code (you will get a different IP address) and cross your fingers 🤞, make sure you have internet enabled as well (just in case).

    The debugging command I used is the following one, which downloads the file needed for California housing:

    !wget https://ndownloader.figshare.com/files/5976036 --timeout 3
    

    Here is a screenshot where it did not work (HTTP 403)
    image

    Here is a screenshot where it did work (HTTP 200):
    image

  18. gigit0000 commented on Jun 18, 2024

    @gigit0000

    I tried on Kaggle notebooks and it seems like indeed the problem happens from time to time. The work-around is to click on the power button (Stop session), reexecute the code (you will get a different IP address) and cross your fingers 🤞,

    @lesteve Thanks for your comment. Yes, that's exactly what I did. I just reported to possibly help troubleshoot this issue :)

  19. lesteve commented on Jun 19, 2024

    @lesteve
    Member

    Some kind of summary comment:

  20. gigit0000 commented on Jun 20, 2024

    @gigit0000

    @lesteve Thank you!

  21. lesteve commented on Jul 3, 2024

    @lesteve
    Member

    I got an answer from Figshare support saying that they fixed the issue. I tried roughly 10 times on Colab and the same on Kaggle notebooks and I was not able to reproduce the issue 🎉.

    I am going to close this one, if you encounter the issue again please comment in this issue!

    You can also try the documented work-arounds in #28297 (comment) and mention in case that does not fix the issue.

  22. gigit0000 commented on Jul 4, 2024

    @gigit0000

    @lesteve Great support - thank you!!!

  23. khyarih commented on Dec 30, 2025

    @khyarih

    Got the same Forbidden error today, i'm using a linux server tried to use some VPNs but didn't work

  24. lesteve commented on Dec 31, 2025

    @lesteve
    Member

    See #32961 this is a known issue on the Figshare side. There is not much we can do unfortunately.

    Please refrain from commenting on old closed issues 🙏.

  25. worldart commented on Jan 5, 2026

    @worldart

    Same error on GoogleColab and my local computer.

    Code:

    from sklearn.datasets import fetch_california_housing
    
    housing = datasets.fetch_california_housing(as_frame=True)
    

    Below is the error.

    NameError                                 Traceback (most recent call last)
    [/tmp/ipython-input-2285489921.py](https://localhost:8080/#) in <cell line: 0>()
          1 from sklearn.datasets import fetch_california_housing
          2 
    ----> 3 housing = datasets.fetch_california_housing(as_frame=True)
          4 X, y = housing.data, housing.target * 10
    
    NameError: name 'datasets' is not defined
    
  26. locked and limited conversation to collaborators on Jan 6, 2026
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions