Error! blahfile is not UTF-8 encoded. Saving disabled
Asked Answered
P

2

19

So, I'm trying to write a gzip file, actually from the net, but to simplify I wrote some very basic test.

import gzip
LINES = [b'I am a test line' for _ in range(100_000)]
f = gzip.open('./test.text.gz', 'wb')
for line in LINES:
    f.write(line)
f.close()

It runs great, and I can see in Jupyter that it has created the test.txt.gz file in the directory listing. So I click on it expecting a whole host of garbage characters indicative of a binary file, like you would see in Notepad.
However, instead I get this ...

Error!  test.text.gz is not UTF-8 encoded.
Saving disabled.
See console for more details

Which makes me think, oh my god, coding error, something is wrong with my encoding, my saving, can I save bytes ? Am I using the correct routines ?? And then spend 5 hours trying all combinations of code and modules.

Presence answered 9/4, 2020 at 5:7 Comment(0)
P
50

The very simple answer to this is none of the above. This is a very misleading error message, especially when the code you've written was designed to save a binary file with a weird extension.

What this actually means is ...

    I HAVE NO IDEA HOW TO DISPLAY THIS DATA ! - Yours Jupyter

So, go to your File Explorer, Finder navigate to the just saved file and open it. Voila !! Everything worked exactly as planned, there is no error.

Hope this saves other people many hours of debugging, and please Jupyter, change your error message.

Presence answered 9/4, 2020 at 5:7 Comment(1)
I had the same problem in Oct 2022 -- with the same solution.Omniscience
T
0

It is also possible to select the file and, instead of double-clicking to open, go to 'view' as it interprets it correctly (or well, mostly, depending on special characters, mine is in Spanish and apparently it doesn't support accents).

This way we can avoid looking for the directory where we got the file and not getting out of jupyter :)

Tequilater answered 12/11, 2022 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.