EDIT: I moved the last paragraph to the beginning because it's really a Python question, but I left my "manual" method answer in case it helps, too.
Forgot to add this link to Python code on Github. It helped me get started with displaying images using Python and dealing with the headers without altering them. On line 19, I changed it to "image_data = image_file[1].data" because the image was in the HDU [1] instead of HDU [0].
I've had this exact problem when dealing with TESS images - I can't open them in the "usual" software I use for all of my other fits images. Inverting the headers won't solve it, either, because one of the keywords in the first header is needed. If you are only trying to make the change for one image, it's easy to do manually. You can edit the headers in Notepad or any other text editor. Here's the general workaround I use if it's only one file (or a couple of files) - if you need to open a lot then this is too tedious.
- Make a copy of the file and change the extension of the copied version to ".txt"
- Open in a text editor like Notepad (I like Notepad++ better, but any text editor will work)
- Turn on "word wrap" so you can see the header info, there aren't carriage returns or line breaks. Each keyword line is exactly 80 characters long regardless of what info it holds.
- Adjust the width of your text editor to get close to 80 characters wide and you'll see the headers "line up" pretty well but not perfectly. There is almost always a situation where the entire 80 characters are used so there isn't a space between the last character of a keyword line and the first character of the next one which will throw off the word wrapping. But that's ok, just frustrating.
- Look through the header info until you see the beginning of the first extension (probably named "SCI"). It's fine to select and delete the keyword lines you don't need, the ones breaking it up into two HDUs, as long as you don't need the info. Some of them will be entries such as "MISSION= Hubble" or something like that along with info about the pipeline that created it, etc.
- When I've located NAXIS, I put the cursor in front of it and select everything up to the end of the first keyword line in the first HDU which should be "SIMPLE= 1" (or true). The first keyword line with SIMPLE= 1 is 80 characters long and MUST remain 80 characters long or it will break it, so I delte everything between NAXIS and the end of the SIMPLE line. Look to see what the next line is after SIMPLE and delete to the first letter of that keyword. The SIMPLE keyword line is required and should be the first one. Make sure you don't add a carriage return or it'll break the file.
- Save your changes and edit the extension to ".fit" or ".fits" and it should open fine.
As long as keep each chunk of keyword info 80 characters in length, you can manually force it to have only one header so you can view the image. This is, of course, not practical for a large number of images and you could lose data that IS important to you such as the date, etc.
To view fits files without having to edit the header, check out SAOimageDS9. It has never failed me in opening an image fits file with multiple HDUs. If you are trying to work with large sets of images there are other workarounds depending on what you're trying to do. Good luck, I hope this works for you!
fits.open(..., ext=1)
or similar to load the extension HDU directly. If none of that works, my answer deals with the stated question of reordering the file. $\endgroup$