millejoh / emacs-ipython-notebook

Jupyter notebook client in Emacs
http://millejoh.github.io/emacs-ipython-notebook/
GNU General Public License v3.0
1.47k stars 122 forks source link

Can't save IPython notebooks!! #623

Closed vale46 closed 4 years ago

vale46 commented 5 years ago

after upgrading ein in emacs (to 20191117.2312 build version) today, can't save .ipynb files (thru C-x C-s or Emacs dropdown menu EIN Notebook -> File -> Save notebook. This is on a W10 desktop. Also see same behavior on my W10 laptop after upgrading ein.

Can I go back to previous build for the time being? (not familiar how to do that).

Thanks!

Output from ein:log-all buffer

18:01:26:209:` [verbose] Enabling autosaves for nb.ipynb with frequency 300 seconds. @#<buffer *ein:notebooklist http://127.0.0.1:8888*>
18:01:26:571: [verbose] ein:kernel-retrieve-session--success: kernel-id=2c9a7ec0-c30b-4de2-9ffd-77df2f9bf525 session-id=7638751a-d60f-4d5e-a493-a06348ccfbbb @#<buffer *ein:notebooklist http://127.0.0.1:8888*>
18:01:26:571: [verbose] WS start: ws://127.0.0.1:8888/api/kernels/2c9a7ec0-c30b-4de2-9ffd-77df2f9bf525/channels?session_id=7638751a-d60f-4d5e-a493-a06348ccfbbb @#<buffer *ein:notebooklist http://127.0.0.1:8888*>
18:01:29:952: [info] Notebook nb.ipynb is ready @#<buffer *ein:notebooklist http://127.0.0.1:8888*>
18:01:29:953: [verbose] WS opened: ws://127.0.0.1:8888/api/kernels/2c9a7ec0-c30b-4de2-9ffd-77df2f9bf525/channels?session_id=7638751a-d60f-4d5e-a493-a06348ccfbbb @#<buffer *ein:notebooklist http://127.0.0.1:8888*>
18:01:34:073: [verbose] Opened notebooklist at http://127.0.0.1:8888 @#<buffer *ein:notebooklist http://127.0.0.1:8888*>
18:01:44:661: [error] Content save http://127.0.0.1:8888/api/contents/nb.ipynb failed (search-failed ^
) nil. @#<buffer *ein: http://127.0.0.1:8888/nb.ipynb*>
18:01:44:663: [info] Failed to save notebook! @#<buffer *ein: http://127.0.0.1:8888/nb.ipynb*>
18:06:26:874: [error] Content save http://127.0.0.1:8888/api/contents/nb.ipynb failed (search-failed ^
) nil. @#<buffer *Packages*>
18:06:26:876: [info] Failed to save notebook! @#<buffer *Packages*>
millejoh commented 5 years ago

Have you confirmed that the notebook is not actually being saved? On my Win 10 setup I get the error message, but if I close then reopen the notebook I can see that the notebook was saved. If you call M-x ein:dev-start-debug then does emacs open a backtrace buffer that looks similar to the following?

Debugger entered--Lisp error: (search-failed "^\015\n")
  re-search-forward("^\015\n" nil nil)
  request--goto-next-body()
  request--consume-100-continue()
  request--curl-preprocess()
  #f(compiled-function (proc event) #<bytecode 0x3de3151>)(#<process request curl> "finished\n")
  apply(#f(compiled-function (proc event) #<bytecode 0x3de3151>) (#<process request curl> "finished\n"))
  request--curl-callback(#<process request curl> "finished\n")

At the moment this does not look like an issue with ein so reverting to an earlier version isn't likely to help. I'll look into this more and see if I can understand better what is happening.

vale46 commented 5 years ago

Have you confirmed that the notebook is not actually being saved? On my Win 10 setup I get the error message, but if I close then reopen the notebook I can see that the notebook was saved. If you call M-x ein:dev-start-debug then does emacs open a backtrace buffer that looks similar to the following?

Debugger entered--Lisp error: (search-failed "^\015\n")
  re-search-forward("^\015\n" nil nil)
  request--goto-next-body()
  request--consume-100-continue()
  request--curl-preprocess()
  #f(compiled-function (proc event) #<bytecode 0x3de3151>)(#<process request curl> "finished\n")
  apply(#f(compiled-function (proc event) #<bytecode 0x3de3151>) (#<process request curl> "finished\n"))
  request--curl-callback(#<process request curl> "finished\n")

At the moment this does not look like an issue with ein so reverting to an earlier version isn't likely to help. I'll look into this more and see if I can understand better what is happening.

Upon further debugging, I discovered the notebooks I was trying to save were untrusted by jupyter server (which updated over the weekend as part of conda update). This new version (by default) saves notebooks that are trusted. After making these notebooks trusted (using jupyter trust <fn>.ipynb), I can now save the notebooks, but ein still reports "notebook save failed". Not sure if this helps debug the issue.

millejoh commented 5 years ago

The error that ein is reporting is originating request package - it is having a hard time parsing the line endings in the request response. As a temporary fix you can replace the request--goto-next-body function with the following code:

(defun request--goto-next-body (&optional noerror)
  (re-search-forward "^[\r\n|\n]" nil noerror))
vale46 commented 5 years ago

The error that ein is reporting is originating request package - it is having a hard time parsing the line endings in the request response. As a temporary fix you can replace the request--goto-next-body function with the following code:

(defun request--goto-next-body (&optional noerror)
  (re-search-forward "^[\r\n|\n]" nil noerror))

Thx! that fixes the notebook save failed message that ein was reporting. Noticing other issues when I try to execute C-x C-o on an open IPython notebook buffer. I'll post the error logs later on that. Should I open a new issue to work thru that? or continue to post on this thread?

millejoh commented 5 years ago

Yes, better to open a separate issue as my initial guess is that that is not related to Windows getting confused on how line endings are encoded. Thanks.

vale46 commented 4 years ago

Closing this out per above. Thanks for your help!