带有 Google Maps API SSL 错误的 Python Geopy

问题描述

我找到了以下链接
https://towardsdatascience.com/pythons-geocoding-convert-a-list-of-addresses-into-a-map-f522ef513fd6

它简要介绍了如何使用 Google Maps API 获取纬度/经度。但是,当我使用提供的代码时,出现 SSL 错误我有一个可用的 API 密钥,因为我可以获得从下面的第二个代码生成的 URL。

代码

from geopy.geocoders import GoogleV3
AUTH_KEY = "HIDDEN"
geolocator = GoogleV3(api_key=AUTH_KEY)
print(geolocator.geocode("1 Apple Park Way,Cupertino,CA").point) #Apple

错误

HTTPSConnectionPool(host='maps.googleapis.com',port=443): Max retries exceeded with url: /maps/api/geocode/json?address=1+Apple+Park+Way%2C+Cupertino%2C+CA&key=HIDDEN (Caused by SSLError(SSLCertVerificationError(1,'[SSL: CERTIFICATE_VERIFY_Failed] certificate verify Failed: self signed certificate in certificate chain (_ssl.c:1076)')))

我也尝试使用以下方法

代码

import requests
import json
import urllib

# https://developers.google.com/maps/documentation/geocoding/intro
base_url= "https://maps.googleapis.com/maps/api/geocode/json?"
AUTH_KEY = HIDDEN

# set up your search parameters - address and API key
parameters = {"address": "1 Apple Park Way,CA","key": AUTH_KEY}

# urllib.parse.urlencode turns parameters into url
print(f"{base_url}{urllib.parse.urlencode(parameters)}")

r = requests.get(f"{base_url}{urllib.parse.urlencode(parameters)}")

我得到完全相同的错误。奇怪的是,虽然 print(f"{base_url}{urllib.parse.urlencode(parameters)}") 生成的 URL 在我点击时可用。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)