Reputation: 1936
Getting this very strange error when I am trying to load my ipython notebook. Never had it before, and I cannot to my recollection, remember having done anything silly with ipython:
Unreadable Notebook: /path/to/notebooks/results.ipynb NotJSONError('Notebook does not appear to be JSON: u\'{\\n "cells": [\\n {\\n "cell_type": "...',)
which is followed by
400 GET /api/contents/results.ipynb?type=notebook&_=1440010858974 (127.0.0.1) 36.17ms referer=http://localhost:8888/notebooks/results.ipynb
Upvotes: 44
Views: 136469
Reputation: 81
In my case, the issue arose from an update I made to the JSON metadata of the notebook, resulting in this metadata becoming invalid. So, I essentially executed the following command:
cat my_notebook.ipynb > my_notebook.json
Then, I copied and pasted the content of my_notebook.json into an online JSON validator, allowing me to identify the lines in the metadata with issues.
Upvotes: 0
Reputation: 299
I had this issue (Windows 10!), and I have no idea how it happened. The file was on an external memory module and might have been corrupted during the removal of the module from the computer.
Checking the file's content in Notepad, and comparing it with a working notebook, the file was truncated, missing the ending. I copied the final part from the good file, but it still gave the same problem.
Then I tried to open the file in VS Code (try & error!), and VS Code indicated that there was an issue and gave me the character number. Since I didn't know how to navigate to the character number in VS Code, I opened it in Notepad++ and identified where it was, and deleted the entire cell. After that, I was able to open it again in JupyterLab.
Upvotes: 0
Reputation: 1
I have simple fix: Don't just change the file format from .py to .ipyn. Create a new ipyn file, copy all the code into that file, and then fix all the errors after the code is copied, like missing hashtags for notes
Upvotes: -1
Reputation: 21
In JupyterLab, try to open the file with the “JSON” editor instead of the “Notebook” editor.
While it won’t succeed in opening the file, it will readily point out any issues with the file’s formatting.
In my case, the issue was a single comma in “\n”,]
. Once I corrected this, I was able to open my file as a notebook again.
None of the solutions here work for me, I don’t have Visual Studio on the Linux-based server I use at work and I don’t have time to get familiar with it.
Upvotes: 2
Reputation: 31
If you are ready for some more effort and get the file somehow, this method can help you..
If you're a Windows User
C:\Users\user_cur\AppData\Local\Google\Chrome\User Data\Default\Cache\Cache_Data
If you're a Mac User
~/.cache/chromium/Default/Cache/
If you're a Windows User and want to search the keyword across files without the lower/upper case
finest /s /i pdf *.*
If you're a Mac User
grep -a 'pdf scraping'
In the output, you'll get the file name, you need to be too observing while finding the name.
Just open that file in the Notepad++ and following things:
Upvotes: 0
Reputation: 386
I was getting the same error while uploading my Jupyter notebook while using one of the community cloud-based servers of https://www.runpod.io/.
This problem gets solved for me by either waiting for some time (1-2 minutes) post uploading the notebook or by uploading a new one/two times and then trying to open it.
Sharing this incase someone has the same problem and reaches here.
Upvotes: 0
Reputation: 91
you will see this error may be because, you were getting merge conflict in .ipynb file. because of that git adds >>>>>>>> HEAD
thing in .ipynb file which makes is unreadable.
To overcome this issue open .ipynb file in vim editor and then remove the incoming changes or your changes as per your use case.
vim <your-.ipynb-file-path>
To remove incoming changes remove content between these lines<<<<<<<<<< HEAD
==============
. Note:- remove this line as well >>>>>>>>>>>>
this line.
to remove your changes remove content between these lines ==============
>>>>>>>>>>>
. Note:- remove this line as well a <<<<<<<<<< HEAD
Upvotes: 0
Reputation: 1
on ubuntu 20.04, I have file String.ipynb. I had same problem because I coded ơ [ echo 'hello' >> String.ipynb ]. deleting 'hello' in String.ipynb -> I could open my notebook like normal. how did I delete? [ nano String.ipynb ] * move to last line (hello) * -> delete it. I hope my answer help you :D
Upvotes: 0
Reputation: 1
If you use Jupyter-Notebook in VS code, just save it in VS code, close the file and try to open it again by accessing the browser.
Upvotes: 0
Reputation: 1
My native language is not English, but because this problem helped me a part, I came to feedback my solution. The following is translated with translation software: Fundamentally, the file format is messed up due to wrong closing. When opening, the correctness of the json format will be checked first, and an error will be returned if it is found to be wrong. The mess in my file format is not <<<<< or ====== but the lack of commas. Either way, it's best to use a piece of software to detect errors in the json syntax, and then manually fix it yourself. The json website detection provided by the highest praise is available, but the detection errors are not complete, and may need to be detected-modified-detected-modified. Also use vscode to open the file, vscode will prompt the location of the json syntax error, which is also incomplete and needs to be checked and modified multiple times.
The error location provided is more difficult to find. I use nodepad++, and the lower right corner can display how many characters are selected (standard, including line breaks). Then select from the first character until the destination position. Although it's a bit stupid, the main reason is that I didn't find the relevant positioning method.
Upvotes: 0
Reputation: 121
I have changed by ipynb file encoding from UTF-8-BOM to UTF-8, and then it worked.
Upvotes: 0
Reputation: 43
Got this error after conflicts while pushing my code to Github. The code present on the repo was old, and my changes were stashed. Notebook wasn't opening in either Jupyter and github repo. Following above comments, I searched for the part in my code which was giving JSON error,i.e. '<<<<<<<<<<<'
, '======='
and '>>>>>>>>>>'
characters using an online json parser. Then I opened my .ipynb notebook in notepad++ and manually replaced these characters with blank string ''
. After this, the notebook opened on my local Jupyter, and I also pushed the changes to Github.
Upvotes: 0
Reputation: 1
I had the same issue after git merge while using VS Code and Jupyter extension.
VS Code would not open the notebook after the merge conflicts were highlighted in the notebook JSON by git (e.g. <<<<<). One way around it was to highlight the changes and accept one by one using the file viewer in the VSCode git interface.
Alternative that worked for me was to rename the file to .json so that it would open and then search for each instance of <<<<< and accept the incoming change.
Upvotes: -2
Reputation: 1606
Jupyter autosaves in a specific way. It means You have accidentally closed the notebook before properly saving it.
You need to look for three things -
<<<<<<<
and delete those lines.======
and replace those lines with ,
.>>>>>>>
and delete those lines.It will work fine after this.
Upvotes: 7
Reputation: 22459
This is my procedure that usually avoids me groping in the dark.
Usually, I manage to fix the errors quickly.
Upvotes: 6
Reputation: 31
this can be changed to reformat your ipynb file to readable in jupyter notebook. check your other ipynb files(open in notepad) which are working fine with your jupyter notebook, check and compare at the end of the files in notepad. there you can reformat the file which is not working.
Upvotes: 3
Reputation: 71
Yes, the best solution for me was I saved my notebook in HTML format, then opened it in Notepad ++ , delete the long repeated lines of output which were causing my notebook to grow to 45MB, once that cleared, Saved the file back into (.ipynb) format , and was able to opened it with no JSON error. Hope that worked for others as well!
Upvotes: 2
Reputation: 81
The easiest way to recover corrupted Jupyter notebook files, whether it contains text or not (size = 0KB), is to go to the project folder and display the hidden files. Once the hidden files are displayed, you will see a folder named '.ipynb_checkpoints'. Simply open this folder and take the file you want!
Upvotes: 8
Reputation: 19814
Save yourself a headache. Open your .ipynb in any online JSON validator and it will tell you which lines have issues. I used this one.
Upvotes: 32
Reputation: 126
I had this issue from accidentally saving as .txt from github and solved by deleting .txt (leaving .ipynb instead of .ipynb.txt when downloading)
Upvotes: 2
Reputation: 1885
In my case, I am using GitHub to save and share my ipython files with my teammate. When there is a conflict in the code, I had to delete those lines indicating the changes in the conflicting code such as:
>>>>>>>>head
=============
and It works for me.
Upvotes: 22
Reputation: 1441
This happened to me as well. I opened my data.ipynb file using notepad and found out it was blank.
I managed to recover my file by going into the hidden ipynb_checkpoints folder and copying data_checkpoint.ipynb out into my working directory.
In my Mac OS terminal
cd .ipynb_checkpoints
cp data-checkpoint.ipynb \..
Thankfully the codes were preserved. Hope this helps!
Upvotes: 14
Reputation: 1625
I just had the same issue after upgrading from IPython 0.13 (ish) to Jupyter 4.
The problem in my case were a few rogue trailing commas in the JSON, for example the comma following "outputs" in:
...
"language": "python",
"metadata": {},
"outputs": [],
},
After removing the commas, Jupyter/IPython could again read the notebook (and upgraded it to version 4). I hope this helps.
Upvotes: 11