MacOS High OSierra 10.13.6,Python3.7,GeocoderServiceError:[SSL:CERTIFICATE_VERIFY_FAILED]

时间:2018-09-04 22:45:33

标签: python python-3.x ssl geopy

我最近在macOS High OSierra上安装了python 3.7,并花了很长时间尝试使其工作。这个问题是here。目前,我在使用以下代码时遇到问题,想知道是否有人可以提供帮助。

import geopy
geocoder = geopy.geocoders.GoogleV3(domain = "maps.google.co.uk")
geocoder.geocode("Cambridge", exactly_one = False)

导致以下错误:

  

SSLCertVerificationError追溯(最近一次通话)   /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py   在do_open(self,http_class,req,** http_conn_args)1316中
  h.request(req.get_method(),req.selector,req.data,标头,   -> 1317 encode_chunked = req.has_header('Transfer-encoding'))1318
  除了OSError作为err:#超时错误

     
    

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py     in request(self,method,url,body,headers,encode_chunked)1228
    “”“向服务器发送完整的请求。”“”     -> 1229 self._send_request(方法,URL,正文,标头,encode_chunked)1230

         

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py     在_send_request(自身,方法,URL,正文,标头,encode_chunked)中
    1274 body = _encode(body,'body')     -> 1275 self.endheaders(body,encode_chunked = encode_chunked)1276

         

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py     在endheaders(自身,message_body,encode_chunked)中1223
    提高CannotSendHeader()     -> 1224 self._send_output(message_body,encode_chunked = encode_chunked)1225

         

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py     在_send_output(自己,message_body,encode_chunked)1015
    del self._buffer [:]     -> 1016 self.send(msg)1017

         

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py     发送中(自己,数据)         第955章     -> 956 self.connect()         其他957:

         

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py     在connect(self)1391 self.sock =     self._context.wrap_socket(self.sock,     -> 1392 server_hostname = server_hostname)1393

  
     

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py   在wrap_socket(自我,袜子,server_side,do_handshake_on_connect,   prevent_ragged_eofs,server_hostname,会话)       411 context = self,   -> 412个会话=会话       413)

     

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py   在_create(cls,sock,server_side,do_handshake_on_connect,   prevent_ragged_eofs,server_hostname,上下文,会话)       849提高ValueError(“ do_handshake_on_connect不应该为   非阻塞插座”)   -> 850 self.do_handshake()       851除了(OSError,ValueError):

     

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py   在do_handshake(自身,阻止)中1107
  self.settimeout(无)   -> 1108 self._sslobj.do_handshake()1109最后:

     
    

SSLCertVerificationError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败:证书中的自签名证书     链(_ssl.c:1045)

  

在处理上述异常期间,发生了另一个异常:

  

URLError跟踪(最近一次通话)   /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/geopy/geocoders/base.py   在_call_geocoder(自我,网址,超时,原始,请求者,反序列化器,   ** kwargs)       314尝试:   -> 315页=请求者(req,timeout = timeout,** kwargs)       316,但异常除外:

     
    

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py     在打开状态(自我,完整网址,数据,超时)         524     -> 525响应= self._open(req,data)         526

         

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py     在_open中(self,req,data)         第542章真相大白     -> 543'_open',要求)         544,如果结果:

         

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py     在_call_chain(self,chain,kind,meth_name,* args)中         502 func = getattr(handler,meth_name)     -> 503结果= func(* args)         504,如果结果不是None:

         

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py     在https_open(self,req)1359中返回     self.do_open(http.client.HTTPSConnection,req,     -> 1360 context = self._context,check_hostname = self._check_hostname)1361

         

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py     在do_open(self,http_class,req,** http_conn_args)1318中
    除了OSError作为err:#超时错误     -> 1319提高URLError(err)1320 r = h.getresponse()

  
     

URLError:

     

在处理上述异常期间,发生了另一个异常:

     

GeocoderServiceError追溯(最近一次通话)    在()中   ----> 1 geocoder.geocode(“ Cambridge”,fully_one = False)

     

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/geopy/geocoders/googlev3.py   在地址解析中(自我,查询,exact_one,超时,范围,区域,   组件,语言,传感器)       240 logger.debug(“%s.geocode:%s”,自我。名称,网址)       第241章   -> 242 self._call_geocoder(url,timeout = timeout),完全是       243)       244

     

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/geopy/geocoders/base.py   在_call_geocoder(自我,网址,超时,原始,请求者,反序列化器,   ** kwargs)       340如果消息中“超时”:       341提高GeocoderTimedOut('服务超时')   -> 342引发GeocoderServiceError(message)       343       344如果hasattr(page,'getcode'):

     

GeocoderServiceError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败:证书链中的自签名证书   (_ssl.c:1045)

1 个答案:

答案 0 :(得分:0)

请看以下链接:here

我可以通过在该页面上运行第二个命令来使其工作:

123,31,41,59 124,26,31,41