我正在使用Python 3.5和cartopy 0.17。
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
plt.show()
当我尝试执行此操作时,由于库正在尝试下载Natural Earth数据集,我会遇到502 Bad Gateway Error:
Warning (from warnings module):
File "/.local/lib/python3.5/site-packages/cartopy/io/__init__.py", line 260
warnings.warn('Downloading: {}'.format(url), DownloadWarning)
DownloadWarning: Downloading: http://naciscdn.org/naturaleart/110m/physical/ne_110m_coastline.zip
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open h.request(req.get_method(), req.selector, req.data, headers)
File "/usr/lib/python3.5/http/client.py", line 1107, in request self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 934, in _send_output self.send(msg)
File "/usr/lib/python3.5/http/client.py", line 877, in send self.connect()
File "/usr/lib/python3.5/http/client.py", line 1253, in connect super().connect()
File "/usr/lib/python3.5/http/client.py", line 853, in connect self._tunnel()
File "/usr/lib/python3.5/http/client.py", line 832, in _tunnel message.strip()))
OSError: Tunnel connection failed: 502 Bad Gateway
During handling of the above exception, another exception occurred:
File "/.local/lib/python3.5/site-packages/cartopy/io/shapereader.py", line 359, in natural_earth
return ne_downloader.path(format_dict)
File "/usr/lib/python3.5/urllib/request.py", line 1297, in https_open context=self._context, check_hostname=self._check_hostname)
File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open raise URLError(err)
urllib.error.URLError: <urlopen error Tunnel connection failed: 502 Bad Gateway>
502代码指示代理错误,但是我已使用以下键在os.environ中设置了代理,但我仍然遇到相同的错误:
os.environ['HTTP_PROXY']= 'proxyaddress:port'
os.environ['HTTPS_PROXY']= 'proxyaddress:port'
如何通过cartopy告诉urllib3在Python环境中使用代理信息?还有其他可能导致此错误的东西吗?
注意:我正在阅读官方文档here
上的教程