Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

error "Notebook does not appear to be JSON: ''...", #171

Open
arninaud opened this issue May 18, 2017 · 14 comments
Open

error "Notebook does not appear to be JSON: ''...", #171

arninaud opened this issue May 18, 2017 · 14 comments

Comments

@arninaud
Copy link

Hello,
I had a notebook saved in a server with some python code but suddenly I get this error when trying to open it : Unreadable Notebook: /path/FILENAME.ipynb NotJSONError("Notebook does not appear to be JSON: ''...",). Furthermore the notebook is now empty (0 byte). Is there any chance I might see my code again?
Thanks in advance

@takluyver
Copy link
Member

There might be a copy saved in a folder called .ipynb_checkpoints adjacent to the notebook file. If not, then the fact that it's 0 bytes means that the data is lost.

@takluyver
Copy link
Member

Coincidentally, someone just posted a link to how you might be able to recover notebook data from your browser cache:
http://stackoverflow.com/questions/38819322/how-to-recover-deleted-ipython-notebooks/44044643#44044643

@ghost
Copy link

ghost commented Jul 30, 2017

Hello @takluyver. Hope I'm not hijacking this thread. If so I can open a new one if you want me to. Just wanted to share with you that I am also getting this error a lot recently. After saving a notebook and trying to open it later I get "error loading notebook" and references "NotJSONError('Notebook does not appear to be JSON: '{\n "cells": [\n {\n "cell_type": "c...',)".

When I look at the .ipynb file there is "extra" JSON with two sets of opening and closing {}. So I have to delete the second set in order to restore the file. It's as if it's duplicating the JSON - or maybe holding onto bits from previous saves? This is happening a lot and I'm not sure that I've done anything that would change the way Jupyter Notebook saves. I run regular updates via conda. I use Chrome as the default browser for notebooks.

Do you have any suggestions for troubleshooting this?

@takluyver
Copy link
Member

That's bizarre. Can you share one of the corrupted notebooks in a gist or something?

@ghost
Copy link

ghost commented Aug 3, 2017

Thanks for responding. I apologize for the delay in getting back to you. Let me see if I can re-create the issue in a test file. If I cannot reproduce it, I'll remove the proprietary stuff in one of the files that has the issue and share that with you.

@ghost
Copy link

ghost commented Aug 6, 2017

Ok I wrote some test code and saved and went to open and got the error. This happens in both Chrome and Firefox. The JSON from the ipynb file is at https://gist.github.com/2ndg33r/d29c539309349859d76c4787a2bd41cd#file-20170806_recreate_notebook_issue-txt. You can see at line 291 is where it goes wrong. Line 292 is another closing } which is out of place. Interestingly, this only happens on Windows. I ran the same thing in a notebook on a Linux machine and I don't have this problem. At least I haven't yet...so perhaps it's something with my Windows build. I even replicated the Pandas code errors and on Linux and the notebook opens without an issue.

Thanks for your time.

@takluyver
Copy link
Member

That's weird - it looks like a valid notebook has been written over a slightly longer notebook file several times, without truncating the file. You can see the ending of a notebook on line 290, line 292, line 342, and line 385. The resulting file is certainly invalid, but if you cut it off at line 290, it's a valid notebook that I can open.

I don't know what would cause that. Do you have any custom configuration or anything? Is there anything unusual about the filesystem you're saving it on? What Python version are you running the notebook server in? Can you try uninstalling and reinstalling Jupyter, or even Python itself?

It's possible that we're doing something wrong on saving files on Windows, but if we were I think we'd have been inundated with reports of it already.

@ghost
Copy link

ghost commented Aug 7, 2017

Yeah I agree. I didn't see really any other issue reports similar to this and is working fine on another system so this doesn't seem to be an issue with Jupyter Notebook. The changes I made to the jupyter config file is the c.NotebookApp.notebook_dir points to an external drive. And I changed the default browser. I think I'll start with restoring the default notebook_dir and see what happens with that.

@takluyver
Copy link
Member

External as in USB hard drive, or as in a network disk? My best guess is that that's the source of the issue, but it's still really weird.

@ghost
Copy link

ghost commented Aug 8, 2017

External USB. You were right that was the issue. Since restoring the notebook directory to my local drive I haven't had any problems. Thanks for your time on this.

@takluyver
Copy link
Member

No problem. I'm still curious about what's going on - I don't think we do anything particularly unusual to write files. But unless you're willing to invest quite a bit of time investigating it, I think it has to go down as something we can't fix.

@Shadhopson
Copy link

Hey there! Just adding on that I'm also getting Unreadable Notebook: NotJSONError('Notebook does not appear to be JSON: u'{\n "cells": [\n {\n "cell_type": "...',) randomly when I open my jupyter notebook files. It happened twice in the last month, though it had never happened before hand. Just to note, I use Linux.

@Nicholas-Autio-Mitchell

I would suggest looking into the raw .ipnb file using a text editor. You might be able to just find the error by having a quick look.

I have done this in the past and found there was a "diff" in there, resulting from a bad/unfinished Git conflict. Jupyter can't open a file in this state as the conflict basically leaves a syntax error in the JSON, which cannot then be parsed.

In my case, I was able to manually delete one of the parts - the notebook then opened as usual.

Example - it might look something like this:

 <<<<<<< HEAD:mergetest
 This is my third line
 =======
 This is a fourth line I am adding
 >>>>>>> 4e2b407f501b68f8588aa645acafffa0224b9b78:mergetest

So you would just delete one side of this, leaving for example:

 This is a fourth line I am adding

Source of conflict example.

@max777888
Copy link

just open the ipynb file with a text editor and check the latest line in the file
usually the problem is with a long line after the last curly braces }
just remove that long line and it will work

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants