我在[geopy][1]
应用程序中使用Python 3.6
,我必须在使用Windows 2012 Server
的过时机器上运行它。从应用程序在此服务器上调用此库时会出现问题,因为它返回以下错误:
File "C:\ServAPI\Util.py", line 12, in getLocation
location = geolocator.geocode(name)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\geopy\geocoders\osm.py", line 193, in geocode
self._call_geocoder(url, timeout=timeout), exactly_one
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\geopy\geocoders\base.py", line 171, in _call_geocoder
raise GeocoderServiceError(message)
geopy.exc.GeocoderServiceError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)
如何解决此问题?我正在Python 3.6.0
Windows 2012 Server
更新
代码是下一个:
from geopy.geocoders import Nominatim
from geopy.exc import GeocoderTimedOut
def getLocation(name):
geolocator = Nominatim()
try:
location = geolocator.geocode(name, timeout=5)
return location
except GeocoderTimedOut as e:
print("Error: geocode failed on input %s with message %s" % (e.msg))
答案 0 :(得分:1)
我遇到了同样的问题,但最终还是要安装SSL和Certifi。我不确定是否有其他人会遇到这个问题,但如果有的话,我就是这样解决的。
首先安装Certifi和SSL软件包,然后
import certifi
import ssl
import geopy.geocoders
from geopy.geocoders import Nominatim
ctx = ssl.create_default_context(cafile=certifi.where())
geopy.geocoders.options.default_ssl_context = ctx
geolocator = Nominatim(scheme='http')
location = geolocator.reverse("48.8588443, 2.2943506")
print(location.address)
print (location.raw)
然后,结果是:
Tour Eiffel, 5, Avenue Anatole France, Gros-Caillou, 7e, Paris, Île-de-France, France métropolitaine, 75007, France
{'place_id': '62005962', 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': '5013364', 'lat': '48.8582602', 'lon': '2.29449905431968', 'display_name': 'Tour Eiffel, 5, Avenue Anatole France, Gros-Caillou, 7e, Paris, Île-de-France, France métropolitaine, 75007, France', 'address': {'attraction': 'Tour Eiffel', 'house_number': '5', 'pedestrian': 'Avenue Anatole France', 'suburb': 'Gros-Caillou', 'city_district': '7e', 'city': 'Paris', 'county': 'Paris', 'state': 'Île-de-France', 'country': 'France', 'postcode': '75007', 'country_code': 'fr'}, 'boundingbox': ['48.8574753', '48.8590465', '2.2933084', '2.2956897']}
答案 1 :(得分:0)
最后,我有解决方案:
win2012
库可能已过时SSL
。因此,解决方案是明确指出schema
是http
:
正确的代码是:
from geopy.geocoders import Nominatim
from geopy.exc import GeocoderTimedOut
def getLocation(name):
geolocator = Nominatim(scheme='http')
try:
location = geolocator.geocode(name, timeout=5)
return location
except GeocoderTimedOut as e:
print("Error: geocode failed on input %s with message %s" % (e.msg))
答案 2 :(得分:0)
这对我有用
function TDisposMethods.DownloadUpdate(FileName: String): TFileStream;
begin
Result := TFileStream.Create(path, fmOpenRead or fmShareDenyNone);
GetInvocationMetadata.ResponseContentType := 'application/*';
end;
答案 3 :(得分:0)
您好,这个代码对我有用,因为我遇到了geopy.geocoders Nomimatim错误。
from geopy.geocoders import ArcGIS
from geopy.exc import GeocoderTimedOut
def getLocation(name):
geolocator = ArcGIS(scheme='http')
try:
location = geolocator.geocode(name, timeout=5)
return location
except GeocoderTimedOut as e:
print("Error: geocode failed on input %s with message %s" % (e.msg))