HDF4Error: SD (59): HDF Internal error

604 views Asked by At

I am trying to download a hdf file and read it python as follows

from pyhdf import SD

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

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

It works but soon after the I am getting the following Error:

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

There are 1 answers

0
John Zwinck On BEST ANSWER

You need to open the output file in binary mode:

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

Better would be to use with to automatically close the file:

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