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

avatar
Borislav Hadzhiev

Last updated: Apr 13, 2024
3 min

banner

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

The Jupyter Notebook error "'_xsrf' argument missing from post" occurs when your currently opened Jupyter Notebook window glitches.

The first thing you should try is to open another existing notebook on the same kernel.

  1. Click on File and then select Open....
  2. Select another existing notebook (.ipynb file).

select file open

You can also select File and then New Notebook and create a new notebook if you don't already have another existing notebook.

select file new notebook

Make sure to create the new notebook on the same kernel.

Go back to the notebook that was showing the "'_xsrf' argument missing from post" error and save it.

save notebook

If you've already closed the browser window that was showing the xsrf error, focus your terminal and scroll up until you see the http://localhost link and click on it.

find and click localhost link in terminal

You can also issue the jupyter notebook list command in another terminal tab to get the link.

shell
jupyter notebook list

issue jupyter notebook list command

# Try opening the /tree endpoint and refresh your browser

If the error persists, try to visit the /tree endpoint, e.g. http://localhost:8888/tree and refresh your browser.

visit tree endpoint

Once you visit the /tree endpoint in your browser, refresh the page.

Then, click on New and reopen the kernel.

# Try to open the page in another browser tab

  1. If the error persists, copy the http://localhost:8888/?token=XYZ page from your terminal (or browser address bar).

find and click localhost link in terminal

You can also issue the jupyter notebook list command in another terminal tab to get the link.

shell
jupyter notebook list

issue jupyter notebook list command

  1. Paste the link into a new browser tab.
  2. Switch back to the browser tab in which you got the _xsrf error and try to save your notebook.

You can also try to paste the link into a new browser window and then switch back to the original window.

# Launching Jupyter Lab with the xsrf checks disabled

Another thing you can try is to launch Jupyter Lab with the XSRF checks disabled.

Run the following command from your terminal.

shell
jupyter lab --ServerApp.disable_check_xsrf=True

launch jupyter lab with xsrf checks disabled

# Try to download the notebook

Another thing you can try is to download the notebook.

  1. Click on File, hover over Download as and select Notebook (ipynb).

file download as ipynb

  1. Click on File, then Open and open the downloaded .ipynb file.

click on file open then open download ipynb file

# Try to interrupt the Kernel

If none of the suggestions helped:

  1. Click on Kernel in the top menu.

  2. Click on Interrupt.

try to interrupt the kernel

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.