使用 Python 3.4,我安装了以下地理定位包
https://pypi.python.org/pypi/geolocation-python/0.2.2
我使用下面的代码在 IDLE 中对其进行了测试
key = 'myGoogleKey'
google = GoogleMaps(api_key=key)
addr = 'Boston MA'
location = google.search(location=addr)
它在最后一行失败,生成 SSL 错误
Traceback (most recent call last):
File "c:\python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 559, in urlopen
body=body, headers=headers)
File "c:\python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 345, in _make_request
self._validate_conn(conn)
File "c:\python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 782, in _validate_conn
conn.connect()
File "c:\python34\lib\site-packages\requests\packages\urllib3\connection.py", line 250, in connect
ssl_version=resolved_ssl_version)
File "c:\python34\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 285, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "c:\python34\lib\ssl.py", line 365, in wrap_socket
_context=self)
File "c:\python34\lib\ssl.py", line 583, in __init__
self.do_handshake()
File "c:\python34\lib\ssl.py", line 810, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\python34\lib\site-packages\requests\adapters.py", line 370, in send
timeout=timeout
File "c:\python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 588, in urlopen
raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
location = google.search(location=addr)
File "c:\python34\lib\site-packages\geolocation\main.py", line 18, in search
return self.geocode.search(location, lat, lng)
File "c:\python34\lib\site-packages\geolocation\geocode\main.py", line 48, in search
data = self.client.get_data(address=address, latitude=latitude, longitude=longitude)
File "c:\python34\lib\site-packages\geolocation\geocode\client.py", line 40, in get_data
return self.send_data(self.API_URL, self.query_parameters)
File "c:\python34\lib\site-packages\geolocation\client.py", line 22, in send_data
response = requests.get(url, params=params)
File "c:\python34\lib\site-packages\requests\api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "c:\python34\lib\site-packages\requests\api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "c:\python34\lib\site-packages\requests\sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "c:\python34\lib\site-packages\requests\sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "c:\python34\lib\site-packages\requests\adapters.py", line 433, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
我在 linux 环境中使用 python 2.7 使用了相同的包和代码,它运行良好。关于如何解决这个问题的任何想法?