Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to solve “forbidden” error in jupyter notebook (conda tab) #2396

Open
CorneeldH opened this issue Apr 11, 2017 · 47 comments
Open

How to solve “forbidden” error in jupyter notebook (conda tab) #2396

CorneeldH opened this issue Apr 11, 2017 · 47 comments

Comments

@CorneeldH
Copy link

I installed anaconda and succeeded in making the conda-tab work thanks to the last suggestion in this entry: http://stackoverflow.com/a/41825208/6375668

However, when I try to create an environment or install an additional package I receive a "forbidden" error (see below). When I open anaconda-navigator I am perfectly able to create environments and install packages. In addition, I changed permissions to the anaconda-folders on my Mac and tried starting jupyter with sudo, but that didn't help.

What could be wrong? And how to fix this? Thanks!

"forbidden error"

@gnestor
Copy link
Contributor

gnestor commented Apr 12, 2017

Are you seeing any notebook server errors in the terminal? What version of the notebook and nb-conda are you running?

Here's a similar issue on nb-conda: anaconda/nb_conda#44

@scaramouche-00
Copy link

Since updating my packages in anaconda (conda update --all) and installing doxygen, I have the same issue. Jupyter will throw the error
403 GET

@faizankshaikh
Copy link

Got the same error. Solved it by opening jupyter in another browser (was using firefox, then used chrome). I think its a "cache" related issue. Maybe someone can explore this futher?

@andreagrandi
Copy link

@faizankshaikh hi, I came to this page because I was having problems saving a notbook while using Firefox. If I use Chrome I don't have any problem, while if I use Firefox I keep getting the "Forbidden" error when I try to save a notebook. I've also tried to disable any extension but it didn't help.

@takluyver
Copy link
Member

#3365 may be related.

takluyver added a commit to takluyver/notebook that referenced this issue Feb 27, 2018
Clearing the secure cookie makes sense when it is invalid or expired,
but clearing it when it's not sent with a request can unexpectedly log
the user out.

I ran into this with misconstructed URLs which didn't incorporate
base_url. That was itself a bug, but the result of suddenly being
unauthenticated makes it harder to track down.

Closes jupytergh-3365 (hopefully)
Possibly also relevant to jupytergh-2396

I'm not sure why this seems to affect Firefox more than Chrome.
@takluyver
Copy link
Member

I've fixed one such issue in #3380, if people want to try that. But there may be more than one problem involved; the precise case I hit could only have come up after PR #2959, which was well after the initial report.

@scaramouche-00
Copy link

Hello, thanks for this! How can we access the patch? I have anaconda and I have tried updating jupyter (conda update jupyter), but it didn't work (still 403 GET).

@takluyver
Copy link
Member

It will need to be merged and released before you can get it through Anaconda. For a small change like this, it's probably easiest to look at what I've changed, find the matching lines in your installation, and apply the change manually.

Otherwise, you could use git to get it:

git clone https://github.com/takluyver/notebook.git
cd notebook
git checkout i3365
pip install .

The last step needs some Javascript tools (see setting up a development environment).

@thomasaarholt
Copy link
Contributor

thomasaarholt commented Mar 15, 2018

Hammering F5 (refresh) seems to be a quickfix for this issue.

@israelzuniga
Copy link

I was having the same 403 status code. The solution was using Jupyter Notebook with Chrome instead of Firefox. I used to blame SELinux configuration.

Here are my details:

OS:

Linux brm10925-pc 4.15.7-300.fc27.x86_64 #1 SMP Wed Feb 28 17:53:39 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Fedora release 27 (Twenty Seven)

Firefox

58.0.2 (64-bit)

Python

Python 3.6.4

Anaconda

conda 4.3.34

Packages in virtualenv (created with anaconda):

backports                 1.0                      py36_1    conda-forge
backports.functools_lru_cache 1.5                      py36_0    conda-forge
blas                      1.1                    openblas    conda-forge
bleach                    2.1.3                      py_0    conda-forge
bokeh                     0.12.14                  py36_0    conda-forge
ca-certificates           2018.1.18                     0    conda-forge
certifi                   2018.1.18                py36_0    conda-forge
click                     6.7                        py_1    conda-forge
cloudpickle               0.5.2                      py_0    conda-forge
cycler                    0.10.0                   py36_0    conda-forge
cytoolz                   0.9.0.1                  py36_0    conda-forge
dask                      0.17.1                     py_2    conda-forge
dask-core                 0.17.1                     py_0    conda-forge
dbus                      1.10.22                       0    conda-forge
decorator                 4.2.1                    py36_0    conda-forge
distributed               1.21.3                   py36_0    conda-forge
entrypoints               0.2.3                    py36_1    conda-forge
expat                     2.2.5                         0    conda-forge
fontconfig                2.12.6                        0    conda-forge
freetype                  2.8.1                         0    conda-forge
gettext                   0.19.8.1                      0    conda-forge
glib                      2.55.0                        0    conda-forge
gmp                       6.1.2                         0    conda-forge
gst-plugins-base          1.8.0                         0    conda-forge
gstreamer                 1.8.0                         1    conda-forge
heapdict                  1.0.0                    py36_0    conda-forge
html5lib                  1.0.1                      py_0    conda-forge
icu                       58.2                          0    conda-forge
ipykernel                 4.8.2                    py36_0    conda-forge
ipython                   6.2.1                    py36_1    conda-forge
ipython_genutils          0.2.0                    py36_0    conda-forge
ipywidgets                7.1.2                    py36_0    conda-forge
jedi                      0.11.1                   py36_0    conda-forge
jinja2                    2.10                     py36_0    conda-forge
jpeg                      9b                            2    conda-forge
jsonschema                2.6.0                    py36_1    conda-forge
jupyter                   1.0.0                    py36_0    conda-forge
jupyter_client            5.2.3                    py36_0    conda-forge
jupyter_console           5.2.0                    py36_0    conda-forge
jupyter_core              4.4.0                      py_0    conda-forge
kiwisolver                1.0.1                    py36_1    conda-forge
libffi                    3.2.1                         3    conda-forge
libgfortran               3.0.0                         1  
libiconv                  1.15                          0    conda-forge
libpng                    1.6.34                        0    conda-forge
libsodium                 1.0.15                        1    conda-forge
libxcb                    1.12                          1    conda-forge
libxml2                   2.9.7                         0    conda-forge
locket                    0.2.0                    py36_1    conda-forge
markupsafe                1.0                      py36_0    conda-forge
matplotlib                2.2.0                    py36_0    conda-forge
mistune                   0.8.3                      py_0    conda-forge
msgpack-python            0.5.5                    py36_0    conda-forge
nbconvert                 5.3.1                      py_1    conda-forge
nbformat                  4.4.0                    py36_0    conda-forge
ncurses                   5.9                          10    conda-forge
notebook                  5.4.0                    py36_0    conda-forge
numpy                     1.14.2          py36_blas_openblas_200  [blas_openblas]  conda-forge
openblas                  0.2.20                        7    conda-forge
openssl                   1.0.2n                        0    conda-forge
packaging                 17.1                       py_0    conda-forge
pandas                    0.22.0                   py36_0    conda-forge
pandoc                    2.1.2                         0    conda-forge
pandocfilters             1.4.1                    py36_0    conda-forge
parso                     0.1.1                      py_0    conda-forge
partd                     0.3.8                    py36_0    conda-forge
patsy                     0.5.0                    py36_0    conda-forge
pcre                      8.41                          1    conda-forge
pexpect                   4.4.0                    py36_0    conda-forge
pickleshare               0.7.4                    py36_0    conda-forge
pip                       9.0.1                    py36_1    conda-forge
prompt_toolkit            1.0.15                   py36_0    conda-forge
psutil                    5.4.3                    py36_0    conda-forge
ptyprocess                0.5.2                    py36_0    conda-forge
pygments                  2.2.0                    py36_0    conda-forge
pyparsing                 2.2.0                    py36_0    conda-forge
pyqt                      5.6.0                    py36_4    conda-forge
python                    3.6.4                         0    conda-forge
python-dateutil           2.7.0                      py_0    conda-forge
pytz                      2018.3                     py_0    conda-forge
pyyaml                    3.12                     py36_1    conda-forge
pyzmq                     17.0.0                   py36_3    conda-forge
qt                        5.6.2                         7    conda-forge
qtconsole                 4.3.1                    py36_0    conda-forge
readline                  7.0                           0    conda-forge
scikit-learn              0.19.1          py36_blas_openblas_201  [blas_openblas]  conda-forge
scipy                     1.0.0           py36_blas_openblas_201  [blas_openblas]  conda-forge
seaborn                   0.8.1                    py36_0    conda-forge
send2trash                1.5.0                      py_0    conda-forge
setuptools                38.5.2                   py36_0    conda-forge
simplegeneric             0.8.1                    py36_0    conda-forge
sip                       4.18                     py36_1    conda-forge
six                       1.11.0                   py36_1    conda-forge
sortedcontainers          1.5.9                    py36_0    conda-forge
sqlite                    3.20.1                        2    conda-forge
statsmodels               0.8.0                    py36_0    conda-forge
tblib                     1.3.2                    py36_0    conda-forge
terminado                 0.8.1                    py36_0    conda-forge
testpath                  0.3.1                    py36_0    conda-forge
tk                        8.6.7                         0    conda-forge
toolz                     0.9.0                      py_0    conda-forge
tornado                   4.5.3                    py36_0    conda-forge
traitlets                 4.3.2                    py36_0    conda-forge
wcwidth                   0.1.7                    py36_0    conda-forge
webencodings              0.5                      py36_0    conda-forge
wheel                     0.30.0                   py36_2    conda-forge
widgetsnbextension        3.1.4                    py36_0    conda-forge
xorg-libxau               1.0.8                         3    conda-forge
xorg-libxdmcp             1.1.2                         3    conda-forge
xz                        5.2.3                         0    conda-forge
yaml                      0.1.7                         0    conda-forge
zeromq                    4.2.3                         2    conda-forge
zict                      0.1.3                      py_0    conda-forge
zlib                      1.2.11                        0    conda-forge

@thomasaarholt
Copy link
Contributor

thomasaarholt commented Mar 28, 2018

@israelzuniga In Firefox, did you try either running Refresh (Ctrl + R or F5) many times after each other, or emptying cache?

@takluyver
Copy link
Member

Also check that you haven't disabled cookies - that breaks Jupyter's authentication. But you'll probably know if you've done that.

There's still the fix from #3380 to be released. I'll try to aim for a new release soon.

@israelzuniga
Copy link

@thomasaarholt Yesterday, after getting things done in Chrome, I tried that with good results (emptying cache, and also reinstalling FF). What didn't work so well, was running refresh (a lot of times) from FF without cache deletion.
This is at my employers' ThinkPad.

Other times, in my macbook for personal use, I have been using Jupyter/IPython and FF without any issues for years. So, now this is a truly interesting situation.

@takluyver Sure. Even I disabled privacy plugins to discard interferences but was related to FF cache and Jupyer session handling. It works better today.

@benelot
Copy link

benelot commented May 9, 2018

Clearing the cache fixed it for me in Chrome:
-Open up Developer Tools and right+click the refresh button
-Choose Empty cache and hard reload
-Profit!

@thomasaarholt
Copy link
Contributor

Thanks for the feedback, @israelzuniga. I oddly didn't see your comment before now.

@tolyla25
Copy link

I concur. Firefox is a root cause. I opened with Opera and it is working fine

@nanodan
Copy link

nanodan commented Jun 26, 2018

I have this same error, but it's occurring in chrome. Clearing the cache does not help in my case.

New file creation:

Launcher Error
Cannot read property 'path' of undefined

Existing file save after edit Error:

File Save Error for filename.txt
Invalid response: 403 Forbidden

@beraug
Copy link

beraug commented Jul 14, 2018

I've fixed using "sudo jupyter notebook": it requests the password and don't initialise as it does not understand the command, but reinstate the cache access (as it lost privileges for some reason). All works fine after that.

(tensorflow) VirtualBox:$ sudo jupyter notebook
[sudo] password for user:
sudo: jupyter: command not found
(tensorflow) VirtualBox:
$ jupyter notebook

@stephenkrol
Copy link

Had this problem today on Chrome. Clearing cache and cookies and then repasting in url with token fixed it.

@Manikgarg
Copy link

Manikgarg commented Jan 8, 2019

Also check that you haven't disabled cookies - that breaks Jupyter's authentication. But you'll probably know if you've done that.

Yes, it works for me after enabling cookies on Safari.

@thinkjrs
Copy link

I also experienced this problem. Like many above, I temporarily opened the notebook in chrome, saved it (in chrome), then closed both the chrome + firefox notebooks before restarting the notebook in Firefox w/o issue.

Unsaved code cells within the broken Firefox session were in the chrome notebook so I am assuming that Chrome was able to read the cache contents while Firefox was not, however, since I'm not a jupyter dev take my jump to conclusion here with a grain of salt.

@rsemenoff
Copy link

I use chrome always, and I get this occassionally. Go your home url (open another tab if necessary) and refresh that page. It will as ask for the authentication token, which can be found in the terminal where the notebook server was started. Once you are logged in (again), go back to your notebook tab and select the "kernel>reconnect" menu item.

@vikash0837
Copy link

vikash0837 commented Mar 27, 2019

It worked for me when i changed the browser. :)
Before that i struggled for an hour with chrome. I still don't know what is the exact issue with chrome
Currently it is working in Mozila firefox

@gnestor
Copy link
Contributor

gnestor commented Apr 1, 2019

Thanks all for sharing your solutions! 🙏

@Shahbaz921
Copy link

Shahbaz921 commented May 10, 2019

Just try clicking the Jupyter icon in the page.

@vivshri
Copy link

vivshri commented Jun 8, 2019

Your AWS session might have been expired. Just re-login.

@YubinXie
Copy link

YubinXie commented Jul 5, 2019

Somehow, I have to re-log in the jupyter session every few days to get over this error.

@kalanaej
Copy link

For get rid of from that error, You have to enable cookies on your browser. Then it will work

@alxy
Copy link

alxy commented Dec 12, 2019

I also get this nasty error in chrome all of a sudden (it has been working for months now). If I use Edge, the problem is gone. Has anybody figured what it could be? I tried refreshing, deleting cache, cookies, reentered the token, ...

But still all requests error out with 403, except for the /login page:

[W 15:19:50.801 NotebookApp] 403 GET /api/sessions?_=1576160390722 (::1) 1.99ms referer=http://localhost:8888/tree
[W 15:19:50.802 NotebookApp] Forbidden
[W 15:19:50.802 NotebookApp] 403 GET /api/terminals?_=1576160390723 (::1) 1.99ms referer=http://localhost:8888/tree
[W 15:20:04.664 NotebookApp] Forbidden
[W 15:20:04.670 NotebookApp] 403 GET /api/sessions?_=1576160390724 (::1) 6.98ms referer=http://localhost:8888/tree
[W 15:20:04.675 NotebookApp] Forbidden
[W 15:20:04.676 NotebookApp] 403 GET /api/terminals?_=1576160390725 (::1) 2.00ms referer=http://localhost:8888/tree

Edit: I just realized using the local IP http://127.0.0.1:8888 instead of http://localhost:8888 works for some obscure reasons... At least for me

@kalanaej
Copy link

kalanaej commented Dec 13, 2019 via email

@alxy
Copy link

alxy commented Dec 13, 2019

I did not disable cookies, and the page indeed does set the cookies. As I said, it does work on 127.0.0.1 in teh exact same browser. In fact, I openend two tabs and in one it works, in the other (localhost) it doesnt.

@vivshri
Copy link

vivshri commented Dec 14, 2019 via email

@jhultman
Copy link

jhultman commented Dec 17, 2019

In case it helps anyone, this error can happen if trying to create notebook in folder owned by another user (such as root). Fix with chown -R <user:group> <folder>.

@jspassov
Copy link

I also get this nasty error in chrome all of a sudden (it has been working for months now). If I use Edge, the problem is gone. Has anybody figured what it could be? I tried refreshing, deleting cache, cookies, reentered the token, ...

But still all requests error out with 403, except for the /login page:

[W 15:19:50.801 NotebookApp] 403 GET /api/sessions?_=1576160390722 (::1) 1.99ms referer=http://localhost:8888/tree
[W 15:19:50.802 NotebookApp] Forbidden
[W 15:19:50.802 NotebookApp] 403 GET /api/terminals?_=1576160390723 (::1) 1.99ms referer=http://localhost:8888/tree
[W 15:20:04.664 NotebookApp] Forbidden
[W 15:20:04.670 NotebookApp] 403 GET /api/sessions?_=1576160390724 (::1) 6.98ms referer=http://localhost:8888/tree
[W 15:20:04.675 NotebookApp] Forbidden
[W 15:20:04.676 NotebookApp] 403 GET /api/terminals?_=1576160390725 (::1) 2.00ms referer=http://localhost:8888/tree

Edit: I just realized using the local IP http://127.0.0.1:8888 instead of http://localhost:8888 works for some obscure reasons... At least for me

  1. create jupyter_notebook_config.py as described here
  2. Uncomment the line c.NotebookApp.allow_remote_access = False
  3. Change it to c.NotebookApp.allow_remote_access = True

It work for me :-)

@davidvancleve
Copy link

davidvancleve commented Feb 2, 2020

Clearing cookies from localhost resolved this for me, in Chrome 79 (Linux).

@pedrodcb
Copy link

pedrodcb commented Feb 5, 2020

Clear your cache then right click on and duplicate your browser tab containing the notebook. It will ask you for the Jupyter password again. Once you enter it successfully just go back to the original window and try saving, everything should work.

@vivianna-121
Copy link

Hammering F5 (refresh) seems to be a quickfix for this issue.

Exactly..

@mhmdmirzaei
Copy link

Probable reason:
One reason could be that your Jupyter is password protected and for some reason you need to re-enter the password.

Solution:
Open a new tab and try to connect to your Jupyter server in the new tab. If you are asked to re-enter the password, enter it and your problem should be solved. Go back to the original Jupyter tab and save the file. If you are not asked for the password, this solution doesn't work for you!

Problems with other solutions:
If you refresh or try to restart Jupyter, you might loose some of the work you haven't been able to save!

@yifanzhang13
Copy link

I've fixed using "sudo jupyter notebook": it requests the password and don't initialise as it does not understand the command, but reinstate the cache access (as it lost privileges for some reason). All works fine after that.

(tensorflow) VirtualBox:$ sudo jupyter notebook [sudo] password for user: sudo: jupyter: command not found (tensorflow) VirtualBox:$ jupyter notebook

I got the same problem today, this works for me.👍

@orwel1984
Copy link

Getting the same problem in MS Visual Studio Code.
Has anyone given that a try?

@EnisBerk
Copy link

I had the same issue on the MS Visual Studio Code,
I set the following in the config as suggested at vscode issue

c.NotebookApp.token = ''
c.NotebookApp.open_browser = False
c.NotebookApp.disable_check_xsrf = True

Also when you run a notebook, the server creates a tmp notebook in the directory jupyter server started, I did not have write access to that folder, that was the second issue.

@ghirardinicola
Copy link

Is the issue solved in newer versions or is it still there?

@stas00
Copy link

stas00 commented Jan 4, 2023

It's still there as of today.

Setting:

c.NotebookApp.token = ''

in ~/.jupyter/jupyter_notebook_config.py did the trick for me.

derived from @EnisBerk's #2396 (comment)

@OnlyBelter
Copy link

OnlyBelter commented Mar 15, 2023

I use chrome always, and I get this occassionally. Go your home url (open another tab if necessary) and refresh that page. It will as ask for the authentication token, which can be found in the terminal where the notebook server was started. Once you are logged in (again), go back to your notebook tab and select the "kernel>reconnect" menu item.

I met this problem and I was unable to save the change. Just log in again from another tab, and return to the old one. The old one can save the change now. Thank @rsemenoff .

@lcd522
Copy link

lcd522 commented Apr 7, 2023

Got the same error. Solved it by opening jupyter in another browser (was using firefox, then used chrome). I think its a "cache" related issue. Maybe someone can explore this futher?

Similar way. I Solved it by refreshing and re-enter my password.

@TommasoIacobellis
Copy link

I solved the problem by uninstalling Jupyter Notebook in the environment where I had the issue, from Anaconda console and then installing it again.

@lorenzznerol
Copy link

lorenzznerol commented Jan 18, 2024

The following answer is only for those who work with a login.

Taking up another answer:

I also get this nasty error in chrome all of a sudden (it has been working for months now). If I use Edge, the problem is gone. Has anybody figured what it could be? I tried refreshing, deleting cache, cookies, reentered the token, ...

But still all requests error out with 403, except for the /login page:

[W 15:19:50.801 NotebookApp] 403 GET /api/sessions?_=1576160390722 (::1) 1.99ms referer=http://localhost:8888/tree
[W 15:19:50.802 NotebookApp] Forbidden
[W 15:19:50.802 NotebookApp] 403 GET /api/terminals?_=1576160390723 (::1) 1.99ms referer=http://localhost:8888/tree
[W 15:20:04.664 NotebookApp] Forbidden
[W 15:20:04.670 NotebookApp] 403 GET /api/sessions?_=1576160390724 (::1) 6.98ms referer=http://localhost:8888/tree
[W 15:20:04.675 NotebookApp] Forbidden
[W 15:20:04.676 NotebookApp] 403 GET /api/terminals?_=1576160390725 (::1) 2.00ms referer=http://localhost:8888/tree

Edit: I just realized using the local IP http://127.0.0.1:8888 instead of http://localhost:8888 works for some obscure reasons... At least for me

This, together with the answer just two cells before that at #2396 (comment) say that you just have to "re-log", that is also why you can enter the login page but no other page. If you work with a login, you need to refresh that login after a few days or weeks. I guess this has nothing to do with the browser, but with the server that you work on.

  • The server might have a weekly logout time or a login limit.
  • Or there might be a trigger to be logged out, for example, I had just run !pip install --upgrade torch and ran into:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
fairseq 1.0.0a0+7818f61 requires cffi, which is not installed.
fairseq 1.0.0a0+7818f61 requires hydra-core<1.1, which is not installed.
fairseq 1.0.0a0+7818f61 requires omegaconf<2.1, which is not installed.
fairseq 1.0.0a0+7818f61 requires sacrebleu>=1.4.12, which is not installed.
torchvision 0.12.0 requires torch==1.11.0, but you have torch 2.1.2 which is incompatible.
torchaudio 0.9.0 requires torch==1.9.0, but you have torch 2.1.2 which is incompatible.
Successfully installed mpmath-1.3.0 nvidia-cublas-cu12-12.1.3.1 nvidia-cuda-cupti-cu12-12.1.105 nvidia-cuda-nvrtc-cu12-12.1.105 nvidia-cuda-runtime-cu12-12.1.105 nvidia-cudnn-cu12-8.9.2.26 nvidia-cufft-cu12-11.0.2.54 nvidia-curand-cu12-10.3.2.106 nvidia-cusolver-cu12-11.4.5.107 nvidia-cusparse-cu12-12.1.0.106 nvidia-nccl-cu12-2.18.1 nvidia-nvjitlink-cu12-12.3.101 nvidia-nvtx-cu12-12.1.105 sympy-1.12 torch-2.1.2 triton-2.1.0

This answer on Stack Overflow at Cannot connect to Jupyter Notebook also says that it could be a pip installation that leads to this:

Using pip to install some packages resulted in confusing the jupyter installation.

No matter whether it is a server timeout or triggered by some installation, there is an easy fix for this, at least if you were just logged out:

  • open another tab of the same browser session,
  • log in on your Jupyter Notebook server there,
  • you can close that tab,
  • go back to the tab that is forbidden,
  • click on "forbidden",
  • and it will give way to work on the page again.

I found this out by following the remarks here to press F5 and the login screen came up, and it seems as if you do not even lose any unsaved work. But the smartest way that makes 100% sure that you are not thrown back to any autosaved time before is to log in at a new tab of the same session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests