Open/edit utf8 fits header in python (pyfits)
<p>I have to deal with some fits files which contain utf8 text in their header. This means basically all functions of the pyfits package do not work. Also <strong>.decode</strong> does not work as the fits header is a class not a list. Does someone know how to decode the header so I can process the data? The actual content is not so important so something like ignoring the letters is fine. My current code looks like this:</p>

<pre><code>hdulist = fits.open('Jupiter.FIT')
hdu = hdulist[0].header
hdu.decode('ascii', errors='ignore')
</code></pre>

<p>And I get:
    AttributeError: 'Header' object has no attribute 'decode'</p>

<p>Functions like:</p>

<pre><code>print (hdu)
</code></pre>

<p>return:</p>

<pre><code>ValueError: FITS header values must contain standard printable ASCII characters; "'Uni G\xf6ttingen, Institut f\xfcr Astrophysik'" contains characters/bytes that do not represent printable characters in ASCII.
</code></pre>

<p>I thought about writing something in the entry so I don't need to care about it. However I can' even retrieve which entry contains the bad characters and I would like to have a batch solution as I have some hundred files.</p>

<p>Looks like <code>PyFITS</code> just doesn't support it (yet?)</p>

<p>From <a href="https://github.com/astropy/astropy/issues/3497" rel="nofollow">https://github.com/astropy/astropy/issues/3497</a>:</p>

<blockquote>
  <p>FITS predates unicode and has never been updated to support anything beyond the ASCII printable characters for data. It is impossible to encode non-ASCII characters in FITS headers.</p>
</blockquote>

python decode fits pyfits