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("https://google.com")
Out[2]: <Response [200]>
.condarc file, which allowed me to work with conda behind my company proxy. However, any request done via a JN (installed in a conda env) was not working. Adding this to my script solved the issue. Not sure why JN is not taking the proxy settings of the .condarc file but in any case this is solving my issue. Thanks
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.
00-startup.py with the above contents in C:\Users\my_username\.ipython\profile_default\startup folder. Issue fixed
Apr 27, 2017 at 4:08
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:[email protected]:8080'
'https_proxy': 'https://gunawan.marbun:[email protected]: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']
1. Ensure you are connected to VPN to office network
2. You can set up proxy before starting notebook or in every notebook
A. before starting
from jupyer notebok, start terminal (From option New on right top)
set HTTP_PROXY=http://fakeserver:fakeport
set HTTPS_PROXY=http://fakeserver:fakeport
jupyter notebook
(This will start notebook in new terminal, with proxy set that can be checked with %env)
B. in every notebook
import sys,os,os.path
os.environ['HTTP_PROXY']="http://fakeserver:fakeport"
os.environ['HTTPS_PROXY']="http://fakeserver:fakeport"
3. in windows, set the environmental variables
This PC (Rt Click) >> propertis>> Advanced System Setting >> Advanced >> Envioronmental variables>> click NEW to add 2 variables pointing HTTP_PROXY and HTTPS_PROXY to "http://fakeserver:fakeport"
For those of you who may need a socks5 proxy, the following did the trick for me:
os.environ['http_proxy'] = "socks5h://host:port"
os.environ['https_proxy'] = "socks5h://host:port"
The only difference with the http proxy was the socks5h part in the url. In my case the proxy didn't have username and password but I suppose these too may be added to the url like socks5h://user:passwd@host:port.
Mostly the problem comes due to adding HTTPS in the proxy server URL. For both HTTP and HTTPS, the proxy server URL should be "http://" only
import os
os.environ['http_proxy'] = "http://username:complexpassword!@34@serverIP:port"
os.environ['https_proxy'] = "http://username:complexpassword!@34@serverIP:port"
import requests
requests.get("https://google.com")
Response should be 200 OK
If you are in a Windows domain and use domain\username for authentication, just use username instead of domain\username in python setting above
HTTPS_PROXYandHTTPS_PROXYenvironment variables, correctly. My HTTPS one was incorrect, and failing similarly.