astroquery: OSError: Header missing END card.
Working with Astropy 5.0 and Astroquery I have detected the following issue:
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/hdu/base.py in _readfrom_internal(cls, data, header, checksum, ignore_missing_end, **kwargs)
405 # that are needed to build the HDU object.
--> 406 header_str, header = _BasicHeader.fromfile(data)
407 except Exception:
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/header.py in fromfile(cls, fileobj)
2076 try:
-> 2077 header_str, cards = parse_header(fileobj)
2078 _check_padding(header_str, BLOCK_SIZE, False)
astropy/io/fits/_utils.pyx in astropy.io.fits._utils.parse_header()
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128)
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<ipython-input-10-2120394a9774> in <module>
1 tap_out = []
2 for output_format in ['fits']:
----> 3 job = Gaia.launch_job("select top 5 * from gaiaedr3.gaia_source", output_format = output_format, dump_to_file=False)
4 tap_out.append(job.get_results())
~/workspace/GaiaPython/AstroqueryProjects/gaia-astroquery-1.0/astroquery/gaia/core.py in launch_job(self, query, name, output_file, output_format, verbose, dump_to_file, upload_resource, upload_table_name)
876 output_file_with_extension = output_file + '.fits.gz'
877
--> 878 return TapPlus.launch_job(self, query=query, name=name,
879 output_file=output_file_with_extension,
880 output_format=output_format,
~/workspace/GaiaPython/AstroqueryProjects/gaia-astroquery-1.0/astroquery/utils/tap/core.py in launch_job(self, query, name, output_file, output_format, verbose, dump_to_file, upload_resource, upload_table_name)
341 self.__connHandler.dump_to_file(suitableOutputFile, response)
342 else:
--> 343 results = utils.read_http_response(response, output_format)
344 job.set_results(results)
345 if verbose:
~/workspace/GaiaPython/AstroqueryProjects/gaia-astroquery-1.0/astroquery/utils/tap/xmlparser/utils.py in read_http_response(response, outputFormat, correct_units)
29 # If we want to use astropy.table, we have to read the data
30 data = io.BytesIO(response.read())
---> 31 result = APTable.read(data, format=astropyFormat)
32
33 if correct_units:
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/table/connect.py in __call__(self, *args, **kwargs)
50 def __call__(self, *args, **kwargs):
51 cls = self._cls
---> 52 out = registry.read(cls, *args, **kwargs)
53
54 # For some readers (e.g., ascii.ecsv), the returned `out` class is not
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/registry.py in read(cls, format, *args, **kwargs)
521
522 reader = get_reader(format, cls)
--> 523 data = reader(*args, **kwargs)
524
525 if not isinstance(data, cls):
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/connect.py in read_table_fits(input, hdu, astropy_native, memmap, character_as_bytes)
209 else:
210
--> 211 hdulist = fits_open(input, character_as_bytes=character_as_bytes,
212 memmap=memmap)
213
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/hdu/hdulist.py in fitsopen(name, mode, memmap, save_backup, cache, lazy_load_hdus, **kwargs)
155 raise ValueError(f'Empty filename: {name!r}')
156
--> 157 return HDUList.fromfile(name, mode, memmap, save_backup, cache,
158 lazy_load_hdus, **kwargs)
159
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/hdu/hdulist.py in fromfile(cls, fileobj, mode, memmap, save_backup, cache, lazy_load_hdus, **kwargs)
393 """
394
--> 395 return cls._readfrom(fileobj=fileobj, mode=mode, memmap=memmap,
396 save_backup=save_backup, cache=cache,
397 lazy_load_hdus=lazy_load_hdus, **kwargs)
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/hdu/hdulist.py in _readfrom(cls, fileobj, data, mode, memmap, save_backup, cache, lazy_load_hdus, **kwargs)
1069
1070 # Make sure at least the PRIMARY HDU can be read
-> 1071 read_one = hdulist._read_next_hdu()
1072
1073 # If we're trying to read only and no header units were found,
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/hdu/hdulist.py in _read_next_hdu(self)
1144 fileobj.seek(offset, os.SEEK_SET)
1145
-> 1146 hdu = _BaseHDU.readfrom(fileobj, **kwargs)
1147 except EOFError:
1148 self._read_all = True
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/hdu/base.py in readfrom(cls, fileobj, checksum, ignore_missing_end, **kwargs)
323 fileobj = _File(fileobj)
324
--> 325 hdu = cls._readfrom_internal(fileobj, checksum=checksum,
326 ignore_missing_end=ignore_missing_end,
327 **kwargs)
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/hdu/base.py in _readfrom_internal(cls, data, header, checksum, ignore_missing_end, **kwargs)
411 # in the wild.
412 data.seek(header_offset)
--> 413 header = Header.fromfile(data,
414 endcard=not ignore_missing_end)
415 hdu_fileobj = data
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/header.py in fromfile(cls, fileobj, sep, endcard, padding)
511 break
512
--> 513 return cls._from_blocks(block_iter, is_binary, sep, endcard,
514 padding)[1]
515 finally:
~/anaconda3/envs/astroquery_gaia/lib/python3.8/site-packages/astropy/io/fits/header.py in _from_blocks(cls, block_iter, is_binary, sep, endcard, padding)
594 # TODO: Pass this error to validation framework as an ERROR,
595 # rather than raising an exception
--> 596 raise OSError('Header missing END card.')
597
598 header_str = ''.join(read_blocks)
OSError: Header missing END card.
The error is caused when this sentence is executed:
tap_out = []
job = Gaia.launch_job("select top 5 * from gaiaedr3.gaia_source", output_format='fits', dump_to_file=False)
job.get_results()
However, if I set ‘dump_to_file=True’,
tap_out = []
job = Gaia.launch_job("select top 5 * from gaiaedr3.gaia_source", output_format='fits', dump_to_file=False)
job.get_results()
Then the table is displayed in Jupyter Notebook without problems.
Please, any advise?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (16 by maintainers)
I can do it if you want @bsipocz
@bsipocz , I reported at github/feedback#11032 . 🤞
off topic, but I wonder @pllim whether you mind reporting it for github as a bug?
Yes, pretty sure it’s an astroquery.gaia issue