Is there a similar config to that of .condarc (anaconda 4.0.0) that allows Jupyter to be configured to work behind a corporate proxy on a local machine?
Error received:
HTTPError: HTTP Error 407: Proxy Authentication Required
Is there a similar config to that of .condarc (anaconda 4.0.0) that allows Jupyter to be configured to work behind a corporate proxy on a local machine?
Error received:
HTTPError: HTTP Error 407: Proxy Authentication Required
Way easier: Just add the following to your notebook:
In [1]: import os
os.environ['http_proxy'] = "http://user:passwd@host:port"
os.environ['https_proxy'] = "https://user:passwd@host:port"
after that, requests will work OK=200, e.g.
In [2]: import requests
requests.get("http://google.com")
Out[2]: <Response [200]>
Based on this link.
You have to modify the Jupyter notebook server env. Create a file named 00-something.py
under your Jupyter notebook server profile and add the following:
For example:
vi /.jupyter/profile_myserver/startup/00-startup.py
(or on Windows open up "C:/Users/your username/.jupyter/profile_myserver/startup/00-startup.py" in your editor of choice)
and add
import sys,os,os.path
os.environ['HTTP_PROXY']="http://proxy.example.com:80"
os.environ['HTTPS_PROXY']="https://proxy.example.com:443"
you can confirm the env variables by running
%env
in a cell and the output
{'CLICOLOR': '1',
'GIT_PAGER': 'cat',
'HOME': '/home/jay',
'HTTP_PROXY': 'http://proxy.example.com:80',
..
Next try
import requests
requests.get("http://google.com")
If you get a response [200] then you are all set.
Use the lowercase variable instead, it works for me:
import sys,os,os.path
os.environ['http_proxy']="http://user:passwd@host:port"
os.environ['https_proxy']="http://user:passwd@host:port"
Then check your env variable using this:
%env
The output will be like this:
{'CLICOLOR': '1',
'...'
'...'
'http_proxy': 'http://gunawan.marbun:xxxxxxxx@cache.itb.ac.id:8080'
'https_proxy': 'https://gunawan.marbun:xxxxxxxx@cache.itb.ac.id:8080'
'no_proxy': 'localhost,127.0.0.0/8,::1'}
Notes: Since I can't comment due to my reputation (req 50 and I'm newbie), I present new answer instead.
An easier solution for me was to add an exception to my proxy configuration. I just put the address http://localhost:8888
to my exception list and it worked.
Based on these Jupyter customization instructions:
.jupyter_config
in your home directoryJUPYTER_CONFIG_DIR=~/.jupyter_config
to your bash/shell profile (eg. .bash_profile
).startup.py
to ~/.jupyter_config
with the following code, customized with your specific proxy information:import os
os.environ['http_proxy']= "http://user:passwd@host:port"
os.environ['https_proxy']= "https://user:passwd@host:port"
os.environ['HTTP_PROXY']= os.environ['http_proxy']
os.environ['HTTPS_PROXY']= os.environ['https_proxy']