403 Forbidden Error - Jupyter Server on Anaconda - jupyter-notebook

By mistake I rebooted my system with open Notebooks in Firefox browser. Ever since I cannot get a Jupyter Server running properly from my Anaconda.
As expected, I can get to the base folder on my system but as soon as I click to open a new folder or notebook the server throws the error Server error: Forbidden at me.
The error seems to be related to login cookies:
[I 08:16:34.286 NotebookApp] 302 GET /?token=1aed47898bede70ff7f27f2518660b343cd64995372d9d58 (127.0.0.1) 0.000000ms
C:\Users\sb123\.conda\envs\Thesis2\lib\site-packages\jupyter_server\base\handlers.py:240: UserWarning: The Tornado web application does not have an 'identity_provider' defined in its settings. In future releases of jupyter_server, this will be a required key for all subclasses of `JupyterHandler`. For an example, see the jupyter_server source code for how to add an identity provider to the tornado settings: https://github.com/jupyter-server/jupyter_server/blob/aa8fd8b3faf37466eeb99689d5555314c5bf6640/jupyter_server/serverapp.py#L253
warnings.warn(
[E 08:16:34.650 NotebookApp] Error unpacking user from cookie: Expecting value: line 1 column 1 (char 0)
[W 08:16:34.650 NotebookApp] Clearing invalid/expired login cookie username-127-0-0-1-8890
[I 08:16:34.651 NotebookApp] 302 GET /server-proxy/servers-info (127.0.0.1) 3.000000ms
[W 08:16:36.070 NotebookApp] Forbidden
[W 08:16:36.070 NotebookApp] 403 GET /api/contents/Documents?type=directory&_=1673594194483 (127.0.0.1) 1.000000ms referer=http://127.0.0.1:8890/tree/Documents
The error can be reproduced across webbrowsers (I tried Firefox and Edge).
When I launch the server from within Pycharm Pro however, I can open, edit and run notebooks without a problem, both in the IDE as well as in Firefox.
I did not find any hints on the web and would be grateful for your support.
Many thanks!

I have exactly the same problem (in a pip venv).
For me, pip install --upgrade 'jupyter-server<2.0.0' did the trick for the time being. This is obviously not a "solution", but so far I have no idea how to find out what is wrong.
I am a single user on a local maching - it seems it has something to do with security. I don't want to deal with complicated login methods. Token based is absolutely sufficient.

Related

Slow Connection to Jupyter Notebook on WSL2

I'm having a weird problem with Jupyter notebook running inside a WSL2 instance. Every time I start a new notebook, my first connection to localhost:8888 (or localhost:XXXX for any other port number) takes a LONG time to connect, like 5-10 minutes. Once one connection to that port has been made, however, all subsequent connections happen at a normal speed. As far as I can tell the delay is not specifically happening within the Jupyter server, as the server output doesn't show any GET requests during the waiting period:
> jupyter notebook .
[I 08:29:21.282 NotebookApp] Authentication of /metrics is OFF, since other authentication is disabled.
[W 08:29:21.729 NotebookApp] All authentication is disabled. Anyone who can connect to this server will be able to run code.
[I 08:29:21.732 NotebookApp] Serving notebooks from local directory: /home/peter/jade_poplar/code/python
[I 08:29:21.732 NotebookApp] Jupyter Notebook 6.4.0 is running at:
[I 08:29:21.732 NotebookApp] http://localhost:8888/
[I 08:29:21.732 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
...
5-10 MINUTES ELAPSE
...
[I 08:38:12.718 NotebookApp] 302 GET / (127.0.0.1) 2.110000ms
However, the issue does appear to be limited only to Jupyter: if I just listen on the port with nc -l 8888 and then point my browser to localhost:8888 the GET request shows up immediately.
I have tried random fixes to other problems that I found on SE, eg. this one, but to no avail. Any advice, or even a suggestion as to where to start looking, would be greatly appreciated! This is driving me bonkers, although I am getting a lot of chess in while I wait for my notebooks to load :D
Old answer
I found 2 ways to get around the "waiting time" on my system.
Hit Ctrl+C once after the console output hangs at Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Set the DISPLAY environment variable to nothing: DISPLAY= jupyter notebook .. Apparently, the same trick works for pip.
UPDATE 1
After some debugging I figured out, that the --no-browser option does the trick as well:
jupyter notebook --no-browser .
jupyter-notebook by default opens localhost:8888 in the browser.
I assume WSL2 has problems opening the default browser, and therefore times out.
UPDATE 2
To confirm my guess, from UPDATE 1, I set up WSL to be able to open a browser window:
Installing firfox in WSL (ubuntu):
sudo apt install firefox
Setting up X11 forwarding on WSL2
Using this setup jupyter-notebook starts normally and localhost:8888 is opened in firefox.

Jupyter lab NetworkError running on WSL2

I am running Jupyter lab on my WSL2 Ubuntu and accessing it in Firefox on my Win10 PC. They are running on the same machine, so there should be no "Network" involved. I am running it as jupyter lab --no-browser. The Server launches just fine in the terminal:
[I 11:17:40.843 LabApp] [jupyter_nbextensions_configurator] enabled 0.4.1
[I 11:17:40.885 LabApp] JupyterLab extension loaded from /home/muthur/anaconda3/lib/python3.8/site-packages/jupyterlab
[I 11:17:40.886 LabApp] JupyterLab application directory is /home/muthur/anaconda3/share/jupyter/lab
[I 11:17:40.888 LabApp] Serving notebooks from local directory: /home/muthur
[I 11:17:40.888 LabApp] Jupyter Notebook 6.2.0 is running at:
[I 11:17:40.888 LabApp] http://localhost:8888/?token=...
[I 11:17:40.888 LabApp] or http://127.0.0.1:8888/?token=...
[I 11:17:40.888 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
But when I start it in my browser, I first get "Server Connection Error: A connection to the Jupyter server could not be established. JupyterLab will continue trying to reconnect. Check your network connection or Jupyter server configuration.", which in the F12 console is due to Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource. Reloading the tab or opening it in a new one gives me the Firefox "Connection failed" error page, saying that it cannot establish a connection to 127.0.0.1:8888
I have been using this setup for the past 2-3 months without issue. Any idea why this crops up now, and how to solve it?
They are running on the same machine, so there should be no "Network" involved.
Believe it or not, there's definitely a network involved when communicating between Windows and a WSL2 session. While WSL1 ran "on" the host Windows network (pseudo-bridged), WSL2 runs in a separate VM that has its own virtual NIC. That NIC is NAT'd behind the Windows interface by default.
This means that port-forwarding is needed, so that when you access port 8888 on localhost (127.0.0.1) in the Windows browser, it is forwarded to the virtual NIC for the WSL2 instance.
By default, this happens automatically (see the localhostForwarding setting on that page). However, sometimes it doesn't. Typically, it "breaks" when Windows is hibernated or shut down with "Fast Restart" enabled (which also does a "mini-hibernate"). Note that Fast Restart is the default in Windows, so it's easy to run into this problem.
The solution is fairly straightforward, assuming that this is the problem that you are seeing:
Exit out of any running WSL instances
wsl --shutdown at the PowerShell or CMD prompt
Restart your WSL instance
Things will hopefully hum along just fine until your next hibernate.
More info and other suggestions to try if that doesn't work at this answer.

How to connect Jupyterhub login with spawned notebook?

i am trying to make jupyterhub with CondorSpawner and LDAPauthentiator work, and I am struggeling with the following problem:
I have spawned a jupyter botebook via jupyter notebook --port=53762 via htcondor and the spawner returns the correct ip and port number. After Jupyterhub starts to connect http://localhost:53762/tree/user/u52383/vjfjfj/ to but when the server redirects to the spawned notebook, it always crashes with the following 404 error (last 2 lines):
16:13:41.229 [ConfigProxy] info: Adding route /tree/user/gabriel/vjfjfj -> http://127.0.0.1:53762
16:13:41.229 [ConfigProxy] info: Route added /tree/user/gabriel/vjfjfj -> http://127.0.0.1:53762
16:13:41.230 [ConfigProxy] info: 201 POST /api/routes/tree/user/gabriel/vjfjfj
[I 2020-10-06 16:13:41.232 JupyterHub users:609] Server gabriel:vjfjfj is ready
[I 2020-10-06 16:13:41.232 JupyterHub log:174] 200 GET /tree/hub/api/users/gabriel/servers/vjfjfj/progress (u52383#::ffff:127.0.0.1) 10363.56ms
[I 2020-10-06 16:13:41.244 JupyterHub log:174] 302 GET /tree/hub/spawn-pending/gabriel/vjfjfj -> /tree/user/gabriel/vjfjfj (u52383#::ffff:127.0.0.1) 0.00ms
16:13:41.258 [ConfigProxy] error: 404 GET /login?next=%2Ftree%2Fuser%2Fgabriel%2Fvjfjfj
[I 2020-10-06 16:13:41.264 JupyterHub log:174] 200 GET /tree/hub/error/404?url=%2Flogin%3Fnext%3D%252Ftree%252Fuser%252Fgabriel%252Fvjfjfj (#127.0.0.1) 0.00ms
It looks like there is some error according to the jupyter notebook since it has been requested at that time
[I 16:13:41.254 NotebookApp] 302 GET /tree/user/u52383/vjfjfj (127.0.0.1) 0.00ms
and the error itself sounds like an login error /login?next=%2Ftree%2Fuser%2Fgabriel%2Fvjfjfj
Does anybody know what causes this crash? Or is there an error with spawning the notebook this way?
Thanks in advance
Gabriel
I resolved this myself, the problem was a security block in the jupyter notebook.
By adding --NotebookApp.token='' the login was succesful.
Note that this is a little unsecure, since everyone on the server can now access the notebook

Jupyter notebook and macOS High Sierra: "osascript: can't open default scripting component"

jupyter-notebook was working fine until I upgraded to macOS High Sierra. Anyone know how to resolve the "osacript: can't open default scripting component" problem? Searching this site and Google yielded no answers. I'm on Anaconda 4.3.24. Thanks.
$ jupyter notebook
[I 08:12:13.340 NotebookApp] The port 8888 is already in use, trying another port.
[I 08:12:13.360 NotebookApp] Serving notebooks from local directory: /Users/Greenhorn/Local/projects
[I 08:12:13.360 NotebookApp] 0 active kernels
[I 08:12:13.360 NotebookApp] The Jupyter Notebook is running at: http://localhost:8889/?token=9d8bde3a675f28b3cbc4c87b7eb0c36788b4d28260d9ed39
[I 08:12:13.360 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 08:12:13.361 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8889/?token=9d8bde3a675f28b3cbc4c87b7eb0c36788b4d28260d9ed39
osascript: can't open default scripting component.
I just ran into exactly the same problem with osascript whilst diagnosing an issue with Emacs Applescript integration (Emacs reports the error as do-applescript: OSA language not available, but further debugging led me to osascript and its can't open default scripting component). I also recently upgraded to High Sierra.
Online one unfortunately finds too much advice that an OSX re-install is required.
In my case, a reboot fixed the issue.
You can diagnose by running the test command:
osascript -e 'tell app "Finder" to display dialog "Hello, World!"'
After the reboot, this should popup a "Hello, World!" dialog.

OpenStack - Web console connection refused

Just getting started with OpenStack.
got everything set up on a Ubuntu VM (under Parallels).
When I attempt to log into the browser console as admin (the password was set during the DevStack install) - I get:
HTTPConnectionPool(host='10.211.55.16', port=8774): Max retries exceeded with url: /v2/a586870bde4c4dfc993dc40cab8047b7/extensions (Caused by <class 'socket.error'>: [Errno 111] Connection refused)
I am however able to run CLI commands such as keystone-tenant-list, and all others, on the actual server.
I made sure that I'm able to ping the virtual Ubuntu host from my Mac. When I first enter http://myhost.mydomain I do get a login page, but, as soon as I enter admin's credentials - I get this ugly (and super long error)
What things could I check to fix this?
Resolution:
1) Wiped clean my Ubuntu host
2) Followed set-by-step instructions here: http://www.stackgeek.com/guides/gettingstarted.html
Everything now works without a glitch.

Resources