2

I have this code:

from astropy.io import fits

filename = tkinter.filedialog.askopenfilename()
file = fits.open(filename)

When trying to run under Python 2.7, everything works fine. But under Python 3.4 there is this problem:

WARNING: An exception occurred matching an HDU header to the appropriate HDU type:  [astropy.io.fits.hdu.base] 
WARNING: The HDU will be treated as corrupted. [astropy.io.fits.hdu.base]

After this warning, I'm unable to perform operations on my file. Any ideas how to handle this problem?

m0nhawk
  • 22,980
  • 9
  • 45
  • 73
Laszlowaty
  • 1,295
  • 2
  • 11
  • 19
  • It worked for me in Python 3.4. Share the FITS file on which it fails. – m0nhawk Apr 25 '15 at 09:42
  • [Here.](https://www.dropbox.com/s/qseo78qj9cqilz2/1SWASP%20J194425.22%2B503106.9.fits?dl=0) It doesn't work for me at all. Here an example file. Funny thing is, it works on python 2.7 – Laszlowaty Apr 25 '15 at 09:52
  • It worked for this file... I believe you need to debug to see what's goes wrong. – m0nhawk Apr 25 '15 at 09:56
  • Unfortunately i don't know how to do this. Can you give me few tips? – Laszlowaty Apr 25 '15 at 11:03
  • For a start, wrap the code into [try-catch](https://docs.python.org/3.4/tutorial/errors.html), so to have additional info on the error. And is it Windows or Linux installation? – m0nhawk Apr 25 '15 at 11:09
  • Under ubuntu 14.04. I'm configuring virtualbox right now, so i can check if problem will occur under windows. – Laszlowaty Apr 25 '15 at 11:49
  • This code is already wrapped by exceptions [here](http://astropy.readthedocs.org/en/latest/_modules/astropy/io/fits/hdu/base.html). Returning warning is executed from exception. – Laszlowaty Apr 25 '15 at 11:56
  • I have tested both in Ubuntu 15.04 and Windows with Anaconda. Works for me. So, maybe there is a problem in other parts of code. – m0nhawk Apr 25 '15 at 14:05
  • it works for me under windows – Laszlowaty Apr 25 '15 at 15:33
  • What does `tkinter.filedialog.askopenfilename()` return? When passing a string/bytes to `fits.open()`, if it doesn't recognize it as an existing filename on the file system it *might* try to parse it as a FITS file. If I just download your example file it reads fine, so the issue probably more likely has to do with what you're passing in from `tkinter.filedialog.askopenfilename()` – Iguananaut Apr 27 '15 at 16:55
  • `tkinter.filedialog.askopenfilename()` is irrelevant. I was checking by running fits.open("file.fits") from simple .py file and it failed as well. Funny think is i switched to debian with fresh python installation and it worked fine. – Laszlowaty Apr 27 '15 at 18:55
  • Probably should just close the question then. It doesn't seem to be reproducible. – Iguananaut Oct 01 '15 at 16:31

0 Answers0