Jupyter Notebook not saving: '_xsrf' argument missing from post

PythonGoogle ChromeAnacondaJupyter Notebook

Python Problem Overview


I've been running a script on jupyter notebooks for about 26 hour; I haven't really been using my computer for anything else, but it needs to run this program that will take ~30 hours to complete. At about 21 hours in, it stopped saving and my terminal had this:

403 PUT /api/contents/[file.ipynb] (::1): '_xsrf' argument missing from POST

where [file.ipynb] is the location of my jupyter notebook. It also says:

'_xsrf' argument missing from post

in the top right part of the notebook again. The program is still running and I don't want to restart jupyter notebook and have to run the program again, as I have a deadline, is there anything else I can do?

I'm using google chrome, but I don't have the LastPass extension or any '%' characters in my code, as another post suggested.

Thanks for any help!

Python Solutions


Solution 1 - Python

The easiest way I found is this:

https://github.com/nteract/hydrogen/issues/922#issuecomment-405456346

Just open another (non-running, existing) notebook on the same kernel, and the issue is magically gone; you can again save the notebooks that were previously showing the _xsrf error.

If you have already closed the Jupyter home page, you can find a link to it on the terminal from which Jupyter was started.

Solution 2 - Python

The solution I came across seems too simple but it worked. Go to the /tree aka Jupyter home page and refresh the browser. Worked.

Solution 3 - Python

The only solution worked for me was:

  1. I opened a new tab in chrome
  2. I pasted : http://localhost:8888/?token=......
  3. then I went to my original notebook and I was able to save it

Solution 4 - Python

I use jupyter notebooks daily and had never experienced this issue before... until today. I had the notebook open all day but it wasn't running anything and then for no apparent reason stopped auto-saving with the '_xsrf' argument missing from POST error message in the top right. FYI - this is a python3 notebook.

I don't know the cause of this problem but I have recently upgraded my python3 version to 3.7.2 and upgraded all of my site-packages to their latest version as of a few days ago which could possibly be the cause.

As for a solution, as suggested in the comment by @AlexK, I opened the same notebook in a new window (different browser in fact), using

jupyter notebook list

in the terminal to get the URL with login token.

This resulted in me having the notebook open and savable again but the information I had entered since the last successful auto-save was missing. Thankfully, my broken instance was still open and working apart from saving so I was able to simply copy and paste the information across then hit save. So, keep the broken instance open if you try this!

Solution 5 - Python

Simply refreshing the tree tab worked for me.

Solution 6 - Python

When I click 'save' button, it has this error. Based on the answers in this post and other websites, I just found the solution. My jupyter notebook is installed from pip. So I access it by typing 'jupyter notebook' in the windows command line.

(1) open a new command window, then open a new jupyter notebook. try to save again in the old notebook, this time ,the error is 'fail: forbidden'

(2) Then in the old notebook, click 'download as', it will pop out a new windows ask you the token.

enter image description here

(3) open another command window, then open another jupyter notebook, type 'jupyter notebook list' copy the code after 'token=' and before :: to the box you just saw. You can save this time. If it fails, you can try another token in the list

Solution 7 - Python

I also came across the same error. I just opened another non-running Juputer notebook and an error is automatically gone.

Solution 8 - Python

In my case, this problem was solved by clicking 'Kernel' (shown on the top of notebooks) and then 'Reconnect'.

Note Added: In some versions of Jupyter, there is not 'Reconnect'.

Solution 9 - Python

1 workaround to solve this problem is:

  1. Download the notebook which you are not able to save by going to: File --> Download as --> Notebook (ipynb).

  2. Open the downloaded notebook by clicking on the downloaded file on the jupyter browser UI

Now, you should be able to save (or rename) this notebook from jupyter UI

Solution 10 - Python

You can disable the XSRF checks by launching e.g. JupyterLab with:

jupyter lab --ServerApp.disable_check_xsrf=True

This probably means that your server is not token-authenticated. For instance, you may have launched JupyterLab with:

jupyter lab --NotebookApp.token='' --NotebookApp.password=''

And it also probably means that you are running JupyterLab on you local machine and your server is not accessible remotely, so this is fine.

But in general beware that if your server doesn't have authentication, it is vulnerable to XSRF.

Solution 11 - Python

I got the same problem (impossible to save either notebooks and .py modules) using an image in the nvidia docker. The solution was just opening a terminal inside jupyter without typing anything but exit once the files were saved. It was done in the same browser/jupyter instance.

Machine OS: Ubuntu 18.04

Solution 12 - Python

I was able to solve it by clicking on the "Kernel" drop down menu and choosing "Interrupt."

Solution 13 - Python

Open the developer setting and click console and type the following

JSON.parse(document.getElementById('jupyter-config-data').textContent).token

Then try saving the Notebook. The notebook that was not saving previously will save now.

Solution 14 - Python

This is the easiest way.

>I did not need to open a new notebook. Instead, I reopened the tree, and reconnected the kernel. At some point I also restarted the kernel. – user650654 Oct 9 '19 at 0:17

Solution 15 - Python

The most voted answer doesn't seem to work when using Jupyter Lab. This one does, however. Just copy the url into a new tab, replace 'lab' with 'tree' and hit enter to load the page. It will generate a new csrf token for your session and you're good to go!

I would suggest enabling Settings > Autosave Documents by default to avoid worrying about losing work in future. It saves very regularly so everything should be up to date before any timeouts happen anyway.

> I did not need to open a new notebook. Instead, I reopened the tree, and reconnected the kernel. At some point I also restarted the kernel. – user650654 Oct 9 '19 at 0:17

Solution 16 - Python

In My Case, I have a close tab of Home Page. After Re-opening the Jupyter.The Error was automatically gone and We can save the file.

Solution 17 - Python

For anyone using jupyterlab on AWS Sagemaker - duplicating the tab is enough to solve the issue.

Solution 18 - Python

The rest of the answers didn't work for me. I went to localhost:8888 and clicked on running, then shut down the notebook from there. Then I swapped back to the original notebook and clicked "don't restart". After that save the notebook and restart it.

Solution 19 - Python

The error was gone just after refreshing the tab of my browser.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionV PView Question on Stackoverflow
Solution 1 - PythoncaxcaxcoatlView Answer on Stackoverflow
Solution 2 - PythonGDBView Answer on Stackoverflow
Solution 3 - PythonsalconteView Answer on Stackoverflow
Solution 4 - PythonBiggsyView Answer on Stackoverflow
Solution 5 - PythonthomaskeefeView Answer on Stackoverflow
Solution 6 - Pythonmusic_pianoView Answer on Stackoverflow
Solution 7 - PythonSweta ShresthaView Answer on Stackoverflow
Solution 8 - PythonToru KikuchiView Answer on Stackoverflow
Solution 9 - PythonSaurabh VermaView Answer on Stackoverflow
Solution 10 - PythonDavid BrochartView Answer on Stackoverflow
Solution 11 - PythonbrzView Answer on Stackoverflow
Solution 12 - Pythonuser14063657View Answer on Stackoverflow
Solution 13 - PythonAakash Avinesh kumarView Answer on Stackoverflow
Solution 14 - PythonliangliView Answer on Stackoverflow
Solution 15 - PythonEdemaRuhView Answer on Stackoverflow
Solution 16 - PythonSuperman_ShieldView Answer on Stackoverflow
Solution 17 - PythonIdodoView Answer on Stackoverflow
Solution 18 - PythonBig DumbView Answer on Stackoverflow
Solution 19 - PythonAnksGView Answer on Stackoverflow