【发布时间】:2021-11-28 02:08:56
【问题描述】:
我正在尝试连接到 Nominatim GeoPy API 以从邮政编码解析纬度/经度坐标。实现如下所示(最小可重复性):
# Create a function that returns lat/lon coordinates from zip code
def get_coord(zip_code):
geolocator = Nominatim(user_agent="GCD Data Client")
location = geolocator.geocode({"postalcode": zip_code, "country": "US"}, exactly_one = True)
in_lat = location.latitude
in_lon = location.longitude
return in_lat, in_lon
# Inputs for data
def get_params(self, zip_code):
# Do error checking to prevent strange, unexpected output from leaving function
out = False
while not out:
try:
in_lat, in_lon = get_coord(zip_code)
# Make sure the lat/lon pair is valid
if abs(in_lat) > 90 or abs(in_lon) > 180:
raise ValueError
out = True
except ValueError:
print("Make sure your lat/lon coordinates are valid (-90-90, -180-180)")
return in_lat, in_lon
if __name__ == '__main__':
# Get some input lats and lons
in_lats = []
in_lons = []
zip_codes = [14201, 80919, 84101] # Dummy data
for zip_code in zip_codes:
in_lat, in_lon = get_params(zip_code)
in_lats.append(in_lat)
in_lons.append(in_lon)
print(in_lats)
print(in_lons)
但是,代码不是问题。当我在本地机器(Windows)上运行此代码时,我得到了预期的纬度/经度坐标。我很确定问题是与 GeoPy 服务器的通信被 AWS 阻止了,因为我在那里运行它时遇到了这个错误:
geopy.exc.GeocoderUnavailable: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?postalcode=14201&country=US&format=json&limit=1 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",),))
我尝试了一些不同的 ec2 安全配置。一种使用默认的 SSH 和 HTTPS(因为这是 443 路由的目标)。我还尝试将它开放给所有入站流量(尽管这是不好的安全做法)以进行测试,因为它只是一个开发服务器(并且此后再次将其锁定:))。在这两种情况下,我仍然遇到同样的问题。这是我需要以某种方式启用的 SSL 设置吗?
【问题讨论】:
-
不,cert nonverify 不是由 AWS 引起的。您在 AWS 上与在 Windows 上运行什么 Python 尤其是 OpenSSL 库,以及使用什么信任库(即 CA 捆绑包)? OpenSSL 1.0.2 无法使用带有“兼容性”链的 LetsEncrypt 证书验证服务器,包括一周前过期的 DST 根,就像包括 nominatim.openstreetmap.org 在内的许多网站一样,如果 DST 根仍在信任库中.请参阅 letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021 和 openssl.org/blog/blog/2021/09/13/LetsEncryptRootCertExpire 以及其他几十个最近的 Stack Q。
标签: amazon-web-services ssl amazon-ec2 https geopy