【问题标题】:Can't unzip downloaded file with Python - Sentinel satellite data无法使用 Python 解压缩下载的文件 - Sentinel 卫星数据
【发布时间】:2019-10-08 08:00:09
【问题描述】:

我无法解压缩从 Copernicus Open Access Hub 下载的 .zip 文件。我检索文件并尝试使用以下 Python 脚本将其解压缩:

from sentinelsat.sentinel import SentinelAPI
import zipfile

user = 's5pguest' 
password = 's5pguest' 

api = SentinelAPI(user, password, 'https://s5phub.copernicus.eu/dhus')

api.download("cb078cce-ed6e-46a7-a614-e13830b2a74a")

# The file is succesfully downloaded

zip_ref = zipfile.ZipFile("S5P_NRTI_L2__CO_____20191001T123303_20191001T123803_10188_01_010302_20191001T131513.zip", 'r')
zip_ref.extractall()
zip_ref.close()

文件已成功下载,但当它尝试解压缩时,我得到:

BadZipFile                                Traceback (most recent call last)
<ipython-input-3-45c213a35459> in <module>
      9 api.download("cb078cce-ed6e-46a7-a614-e13830b2a74a")
     10 
---> 11 zip_ref = zipfile.ZipFile("S5P_NRTI_L2__CO_____20191001T123303_20191001T123803_10188_01_010302_20191001T131513.zip", 'r')
     12 zip_ref.extractall()
     13 zip_ref.close()

~/anaconda3/lib/python3.6/zipfile.py in __init__(self, file, mode, compression, allowZip64)
   1129         try:
   1130             if mode == 'r':
-> 1131                 self._RealGetContents()
   1132             elif mode in ('w', 'x'):
   1133                 # set the modified flag so central directory gets written

~/anaconda3/lib/python3.6/zipfile.py in _RealGetContents(self)
   1196             raise BadZipFile("File is not a zip file")
   1197         if not endrec:
-> 1198             raise BadZipFile("File is not a zip file")
   1199         if self.debug > 1:
   1200             print(endrec)

BadZipFile: File is not a zip file

如果我尝试使用 unzip 从终端解压缩此文件,我会得到:

End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of S5P_NRTI_L2__CO_____20191001T123303_20191001T123803_10188_01_010302_20191001T131513.zip or
        S5P_NRTI_L2__CO_____20191001T123303_20191001T123803_10188_01_010302_20191001T131513.zip.zip, and cannot find S5P_NRTI_L2__CO_____20191001T123303_20191001T123803_10188_01_010302_20191001T131513.zip.ZIP, period.

如果我尝试使用 7zip,我会得到:

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=it_IT.UTF-8,Utf16=on,HugeFiles=on,4 CPUs)

Processing archive: S5P_NRTI_L2__CO_____20191004T113803_20191004T114303_10230_01_010302_20191004T122457.zip

Error: Can not open file as archive

文件似乎已损坏,但如果我尝试下载其他文件,错误仍然存​​在。 我还尝试将名称更改为更简单的名称,例如“doc.zip”,但没有成功。 我被卡住了,有什么想法吗?

我正在关注这个教程https://github.com/acgeospatial/Satellite_Imagery_Python/blob/master/SentinelSat_Demo.ipynb

【问题讨论】:

  • 您确定这是下载的 zip 的正确名称,并且存在于您运行此 python 脚本的同一目录中吗?
  • 你试过用文本编辑器打开它吗?
  • 该文件在同一个脚本文件夹中,但是我也尝试在正确文件夹中 cd 后在命令行上使用 unzip 打开它。
  • 尝试用gedit打开,但是太大导致程序崩溃

标签: python zip geospatial unzip


【解决方案1】:

我认为您的文件可能不是 zip 文件。 转到该文件属性并检查其 .zip 格式是否。

我还想提一下,我无法打开你提到的存储库。

如果你用谷歌搜索 7zip 错误:

【讨论】:

  • 嗨!属性选项卡显示它是一个 .zip 文件。如果您查看我链接的教程,则文件已成功解压缩。我不知道你为什么不能使用我的脚本,你安装了哨兵模块吗?我只是再次运行它并且它工作(仅下载部分)
  • 你好 alcor,我尝试打开 github 存储库,但它不适合我
  • 不,我努力下载哨兵模块,这就是我从代码中删除这些行的原因。你的下载部分很好。文件有问题。
  • 我也在考虑同样的事情。我将向集线器维护人员发送电子邮件以寻求支持。
  • 这不是集线器维护者的事情。尝试从命令行使用 wpget 并手动下载文件也许它会工作
【解决方案2】:

有一个错误:https://github.com/sentinelsat/sentinelsat/issues/270 该文件的 .zip 扩展名不正确。如果我手动将扩展名从 .zip 更改为 .nc 并尝试使用查看器脚本打开它,它可以工作。我想知道我链接的教程如何工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-26
    • 2017-05-24
    • 1970-01-01
    • 2019-06-14
    • 2021-09-04
    • 1970-01-01
    • 2011-09-01
    • 1970-01-01
    相关资源
    最近更新 更多