远程访问NASA MERRA-2数据集时遇权限错误求助
问题:NASA MERRA-2 PM2.5数据访问权限错误排查
我按照NASA官方指南步骤从公共数据库获取PM2.5数据,已在主目录创建.netrc、.urs_cookies、.dodsrc三个文件,且拥有NASA账号。执行以下代码时出现权限相关错误:
ds = xr.open_dataset(URL1).sel(lat=slice(lat1,lat2),lon=slice(lon1,lon2),time=slice(time1,time2))
错误信息如下:
syntax error, unexpected WORD_WORD, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: HTTP^ Basic: Access denied. Output exceeds the size limit. Open the full output data in a text editor --------------------------------------------------------------------------- KeyError Traceback (most recent call last) File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/xarray/backends/file_manager.py:210, in CachingFileManager._acquire_with_cache_info(self, needs_lock) 209 try: ---> 210 file = self._cache[self._key] 211 except KeyError: File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/xarray/backends/lru_cache.py:56, in LRUCache.__getitem__(self, key) 55 with self._lock: ---> 56 value = self._cache[key] 57 self._cache.move_to_end(key) KeyError: [, ('https://goldsmr4.gesdisc.eosdis.nasa.gov/thredds/dodsC/MERRA2_MONTHLY_aggregation/M2TMNXAER.5.12.4_Aggregation.ncml',), 'r', (('clobber', True), ('diskless', False), ('format', 'NETCDF4'), ('persist', False)), '0847945a-4bb6-4085-8032-785c28de3f80'] During handling of the above exception, another exception occurred: OSError Traceback (most recent call last) Input In [3], in () 14 time2 = datetime(2019,12,1,0,30,0) # end date 16 # Read the data for the specified latitude/longitude and date range ---> 17 ds = xr.open_dataset(URL1).sel(lat=slice(lat1,lat2),lon=slice(lon1,lon2),time=slice(time1,time2)) File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/xarray/backends/api.py:526, in open_dataset(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, inline_array, backend_kwargs, **kwargs) 514 decoders = _resolve_decoders_kwargs( 515 decode_cf, ... File src/netCDF4/_netCDF4.pyx:2449, in netCDF4._netCDF4.Dataset.__init__() File src/netCDF4/_netCDF4.pyx:2012, in netCDF4._netCDF4._ensure_nc_success() OSError: [Errno -77] NetCDF: Access failure: 'https://goldsmr4.gesdisc.eosdis.nasa.gov/thredds/dodsC /MERRA2_MONTHLY_aggregation/M2TMNXAER.5.12.4_Aggregation.ncml'
排查方向
1. 身份验证文件配置问题
- 检查
.netrc文件内容格式是否正确,必须为:
替换实际账号密码,同时设置文件权限为machine urs.earthdata.nasa.gov login YOUR_NASA_USERNAME password YOUR_NASA_PASSWORD600(仅当前用户可读可写):chmod 600 ~/.netrc - 确认
.dodsrc文件包含关键配置,替换YOUR_USERNAME为实际用户名:HTTP.COOKIEJAR=/Users/YOUR_USERNAME/.urs_cookies HTTP.NETRC=/Users/YOUR_USERNAME/.netrc HTTP.SSL.CERTIFICATE=/etc/pki/tls/certs/ca-bundle.crt
2. 账号与数据权限
- 登录NASA EarthData账号,确认已完成MERRA-2数据集的授权流程(部分数据集需手动授权访问)。
- 手动访问报错中的URL,用浏览器登录账号后验证是否能正常打开,排查账号锁定或权限缺失问题。
3. 依赖库与环境配置
- 更新
netCDF4和xarray到最新版本,旧版本可能存在身份验证兼容问题:pip install --upgrade netCDF4 xarray - 检查环境变量是否加载
.dodsrc配置:
若未输出正确路径,手动设置环境变量:echo $DODS_CONFIGexport DODS_CONFIG=~/.dodsrc
4. 网络与代理问题
- 若使用代理,在
.dodsrc中添加代理配置:HTTP.PROXY=your_proxy_url:port HTTP.PROXYUSER=proxy_username HTTP.PROXYPASS=proxy_password - 用
curl验证身份连通性:
返回登录页面或成功响应则验证正常,否则检查账号密码正确性。curl -n https://urs.earthdata.nasa.gov
内容的提问来源于stack exchange,提问作者futur3boy
相关产品推荐
相关产品推荐

