my end goal is to retrive a tile map using contextily and ploting (from this example):
import geopandas
import contextily as ctx
df = geopandas.read_file(geopandas.datasets.get_path('nybb'))
df = df.to_crs(epsg=3857)
ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
ctx.add_basemap(ax)
I am using Anaconda behind a company proxy. Proxies are set correctly in the .condarc file:
proxy_servers:
http: http://myproxy.com:8080
https: https://myproxy.com:8080
Package install works fine, and conda config --show
does indeed detect the proxy configuration.
However, I get the following urllib3 error after ctx.add_basemap(ax)
:
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x000001EDD50E66D8>: Failed to establish a new connection
What I don't understand is that despite the proxy configuration, I need to specify the proxy setting to have a basic urllib3 request work.
If no proxy is specified:
http = urllib3.PoolManager()
r = http.request('GET', 'http://httpbin.org/robots.txt')
Out: NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000012FE62B0F98>: Failed to establish a new connection:
But specifying the proxy works:
proxy = urllib3.ProxyManager('http://myproxy.com:8080')
proxy.request('GET', 'http://google.com/')
Out: <urllib3.response.HTTPResponse at 0x12fe6280048>
I would have supposed setting the proxy in Anaconda would handle this for any web related request.
I thought of trying to set the proxy info definitely for urllib3, as I understand is done through urllib.request.install_opener(opener)
in https://stackoverflow.com/a/36881923/12356293, but such an 'opener' doesn't seem to exist for urllib3.
In the end:
- How to specify proxy information using contextily?
- Why setting the proxy information in Anaconda is not enough for urllib3?
Any help is appreciated, thanks.