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

使用sentinelsat下载Sentinel-2影像遇BrokenPipeError错误的解决方法

解决Sentinelsat连接错误:ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))

问题描述

在科研工作中使用sentinelsat工具下载Sentinel-2影像时,反复收到错误提示:ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe')),需解决此问题以获取目标数据。

原始实现代码

import geopandas as gpd
from sentinelsat import*

regional_bnd = "/content/MyDrive/MyDrive/shapefiles/Regional_Boundary/g_accra.shp"
shapefile = gpd.read_file(regional_bnd)
user = "my_username"
password = "my_password"
url = "https://scihub.copernicus.eu/dhus"
api = SentinelAPI(user, password, url)

aoi = None

for geom in shapefile["geometry"]:
  aoi = geom

products = api.query(
    aoi,    
    date = ("20180608", date(2018, 12, 12)),
    platformname = "Sentinel-2",
    processinglevel = "Level-2A",
    cloudcoverpercentage = (0, 30)
)

解决方法

  • 增加请求超时与重试机制:初始化API时设置超时时间和重试次数,避免短暂连接异常直接报错,修改代码如下:
    api = SentinelAPI(user, password, url, timeout=30, retry_attempts=5)
    
  • 优化AOI处理:直接使用shapefile的合并边界,替代循环赋值,减少格式转换可能的问题:
    aoi = shapefile.unary_union
    
  • 拆分日期查询范围:将大跨度日期拆分为多个小时间段查询,降低单次请求的数据负载,例如:
    # 第一阶段查询
    products1 = api.query(aoi, date=("20180608", "20180812"), platformname="Sentinel-2", processinglevel="Level-2A", cloudcoverpercentage=(0,30))
    # 第二阶段查询
    products2 = api.query(aoi, date=("20180813", "20181012"), platformname="Sentinel-2", processinglevel="Level-2A", cloudcoverpercentage=(0,30))
    # 合并结果
    products = {**products1, **products2}
    
  • 检查网络环境:切换至稳定的网络(如科研内网),避免网络波动导致连接管道中断。
  • 更新sentinelsat版本:执行命令升级工具包,修复旧版本的已知连接bug:
    pip install --upgrade sentinelsat
    
  • 调整查询过滤条件:暂时放宽云量限制或减少非必要筛选,先获取数据后再本地二次筛选,降低单次请求的返回数据量。

内容的提问来源于stack exchange,提问作者Akpakli Edudzi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 06:25:29