You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Google Colab中导入fetch_california_housing时出现HTTP 403错误

解决Google Colab中fetch_california_housing偶发HTTP Error 403: Forbidden问题

问题场景

在Google Colab运行以下代码时,会偶发触发HTTP Error 403: Forbidden错误:

from sklearn.datasets import fetch_california_housing
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

housing = fetch_california_housing()

这个错误并非持续存在,属于偶发情况(比如前一天出现,第二天又恢复正常)。

临时修复方法

通过导入warnings模块并全局忽略警告,可以临时绕过该错误,代码如下:

from sklearn.datasets import fetch_california_housing
import warnings # 用于忽略fetch_california_housing的HTTP 403错误
warnings.filterwarnings("ignore") # 屏蔽HTTP 403错误提示

housing = fetch_california_housing()

注意事项

  • 因为错误是偶发的,后续如果不再出现,建议移除忽略警告的代码,防止掩盖其他潜在的异常提示
  • 这类403错误大多是sklearn数据集服务器的临时访问限制导致,一般不需要额外排查本地配置问题

内容的提问来源于stack exchange,提问作者Pho cultist

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 19:39:52