HDF4Error:SD(59):HDF内部错误

时间:2018-02-14 13:33:02

标签: python hdf pyhdf

我正在尝试下载hdf文件并按如下方式读取它:

from pyhdf import SD

file = open("temp.hdf", 'w')
ftp.retrbinary('RETR '+ filename, file.write)
file.close()

hdf=SD.SD('temp.hdf')

它可以工作但很快我得到以下错误:

Traceback (most recent call last):

  File "<ipython-input-46-55805a9d569b>", line 6, in <module>
    hdf=SD.SD('temp.hdf')

  File "/usr/local/lib/python2.7/dist-packages/pyhdf/SD.py", line 1444, in __init__
    _checkErr('SD', id, "cannot open %s" % path)

  File "/usr/local/lib/python2.7/dist-packages/pyhdf/error.py", line 23, in _checkErr
    raise HDF4Error(err)

HDF4Error: SD (59): HDF Internal error

1 个答案:

答案 0 :(得分:3)

您需要以二进制模式打开输出文件:

file = open("temp.hdf", 'wb') # was 'w'

最好是使用with自动关闭文件:

with open("temp.hdf", 'wb') as out:
    ftp.retrbinary('RETR '+ filename, out.write)