2017-04-14 68 views
0

當我嘗試使用google geolocator時,我收到了ssl錯誤。這很奇怪,因爲同一個項目在其他計算機上工作正常。Google python Geolocator:SSL CERTIFICATE_VERIFY_FAILED

下面是代碼:

from geopy.geocodersimport GoogleV3 
geolocator = GoogleV3(my_key) 
location = geolocator.geocode("1 rue Martel, 75010 Paris") 

這裏是問題:

Traceback (most recent call last): 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open 
    encode_chunked=req.has_header('Transfer-encoding')) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request 
    self._send_request(method, url, body, headers, encode_chunked) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request 
    self.endheaders(body, encode_chunked=encode_chunked) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders 
    self._send_output(message_body, encode_chunked=encode_chunked) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output 
    self.send(msg) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send 
    self.connect() 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect 
    server_hostname=server_hostname) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket 
    _context=self, _session=session) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__ 
    self.do_handshake() 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake 
    self._sslobj.do_handshake() 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake 
    self._sslobj.do_handshake() 
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) 

這裏是我的配置: MACOS, geopy 1.11.0, 的Python 3.6.1

非常感謝您的幫助!

+0

你解決了這個問題嗎? –

回答

0

您可能會嘗試在geolocator=分配之前添加以下代碼,以禁用SSL證書驗證作爲臨時措施。

import ssl 

# Disable SSL certificate verification 
try: 
    _create_unverified_https_context = ssl._create_unverified_context 
except AttributeError: 
    # Legacy Python that doesn't verify HTTPS certificates by default 
    pass 
else: 
    # Handle target environment that doesn't support HTTPS verification 
    ssl._create_default_https_context = _create_unverified_https_context 

希望得到這個幫助。