我尝试使用Contextily将底图添加到使用GeoPandas创建的地图中,但收到以下错误:
HTTPSConnectionPool(host='a.tile.openstreetmap.org', port=443): Max retries exceeded with url: /14/8452/7869.png (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
File "D:\generate_udf_maps.py", line 42, in generate_map
ctx.add_basemap(ax, source=ctx.providers.OpenStreetMap.Mapnik)
File "D:\generate_udf_maps.py", line 60, in <module>
generate_map(gdb_path, None, operations_file)下面是我的代码:
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
from shapely.geometry import Point, Polygon
import contextily as ctx
fig, ax = plt.subplots()
p1 = Point(640864.516, 784724.566)
p2 = Point(638594.804, 788492.544)
p3 = Point(644076.197, 788141.637)
p4 = Point(641089.953, 789539.343)
df = gpd.GeoDataFrame(geometry=[p1, p2, p3, p4])
df.plot(ax=ax)
ctx.add_basemap(ax, source=ctx.providers.OpenStreetMap.Mapnik) # Error happens here. If this line is not present I get a map with just the points.
plt.show()我已经尝试了不同的地图提供商,但都无济于事,我看到了几个链接,给出了与参考包相关的建议,我不确定这些建议是否适用于这里。提前感谢!
发布于 2020-07-01 01:40:18
我发现了一个不太理想且不安全的临时解决方案,即通过在C:\path_to_python_libraries\contextily\tile.py,第443行设置verify=False来关闭SSL验证,这样它就变成了:
request = requests.get(tile_url, headers={"user-agent": USER_AGENT}, verify=False)这种解决方案不太理想,但在找到永久解决方案之前,它可以完成这项工作。我仍然希望有一个灵魂在那里,知道如何干净和永久地解决这个问题。
https://stackoverflow.com/questions/62075968
复制相似问题