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

使用Python的cdsapi下载ERA5数据失败(404错误)求助

解决cdsapi下载ERA5数据时的404错误

问题原因分析

报错里的404是因为请求指向了已废弃的beta API地址,同时请求参数存在冗余项,也可能是cdsapi配置文件格式有误。

解决步骤

1. 修正cdsapi配置文件

检查用户目录下的.cdsapirc文件(Windows路径为C:\Users\<你的用户名>\.cdsapirc),确保使用正式API地址,格式如下:

url: https://cds.climate.copernicus.eu/api/v2
key: 你的UID:你的API密钥

若没有该文件,可前往CDS官网生成密钥后手动创建。

2. 清理请求中的冗余参数

原代码里的download_format: 'unarchived'不属于ERA5请求的合法参数,会导致请求异常,需删除。修改后的代码如下:

import cdsapi

dataset = "reanalysis-era5-single-levels"
request = {
    'product_type': ['reanalysis'],
    'variable': ['10m_u_component_of_wind', '10m_v_component_of_wind'],
    'year': ['2024'],
    'month': ['05'],
    'day': ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'],
    'time': ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00'],
    'data_format': 'netcdf',
    'area': [38, 61, 23, 81]
}

client = cdsapi.Client()
client.retrieve(dataset, request).download()

3. 确保cdsapi版本正确

执行命令升级到最新稳定版:

pip install --upgrade cdsapi

若升级后仍有问题,可尝试回退到已知稳定版本(如0.6.1):

pip install cdsapi==0.6.1

4. 确认数据集使用条款

登录CDS官网,进入reanalysis-era5-single-levels数据集页面,确认已同意使用条款,否则会导致请求失败。


内容的提问来源于stack exchange,提问作者Shahid Hussain

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 05:30:15