0
votes

I recently installed python 3.7 on macOS High OSierra and spent ages trying to get it working. That question is here. Currently I am having problems with the below code and wondered if anyone can help.

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

Results in the following error:

SSLCertVerificationError Traceback (most recent call last) /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args) 1316
h.request(req.get_method(), req.selector, req.data, headers, -> 1317 encode_chunked=req.has_header('Transfer-encoding')) 1318
except OSError as err: # timeout error

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py in request(self, method, url, body, headers, encode_chunked) 1228
"""Send a complete request to the server.""" -> 1229 self._send_request(method, url, body, headers, encode_chunked) 1230

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py in _send_request(self, method, url, body, headers, 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 in endheaders(self, message_body, encode_chunked) 1223
raise 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 in _send_output(self, 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 in send(self, data) 955 if self.auto_open: --> 956 self.connect() 957 else:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py in 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 in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session) 411 context=self, --> 412 session=session 413 )

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py in _create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session) 849 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets") --> 850 self.do_handshake() 851 except (OSError, ValueError):

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py in do_handshake(self, block) 1107
self.settimeout(None) -> 1108 self._sslobj.do_handshake() 1109 finally:

SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)

During handling of the above exception, another exception occurred:

URLError Traceback (most recent call last) /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/geopy/geocoders/base.py in _call_geocoder(self, url, timeout, raw, requester, deserializer, **kwargs) 314 try: --> 315 page = requester(req, timeout=timeout, **kwargs) 316 except Exception as error:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout) 524 --> 525 response = self._open(req, data) 526

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py in _open(self, req, data) 542 result = self._call_chain(self.handle_open, protocol, protocol + --> 543 '_open', req) 544 if result:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args) 502 func = getattr(handler, meth_name) --> 503 result = func(*args) 504 if result is not None:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py in https_open(self, req) 1359 return 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 in do_open(self, http_class, req, **http_conn_args) 1318
except OSError as err: # timeout error -> 1319 raise URLError(err) 1320 r = h.getresponse()

URLError:

During handling of the above exception, another exception occurred:

GeocoderServiceError Traceback (most recent call last) in () ----> 1 geocoder.geocode("Cambridge", exactly_one = False)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/geopy/geocoders/googlev3.py in geocode(self, query, exactly_one, timeout, bounds, region, components, language, sensor) 240 logger.debug("%s.geocode: %s", self.class.name, url) 241 return self._parse_json( --> 242 self._call_geocoder(url, timeout=timeout), exactly_one 243 ) 244

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/geopy/geocoders/base.py in _call_geocoder(self, url, timeout, raw, requester, deserializer, **kwargs) 340 if "timed out" in message: 341 raise GeocoderTimedOut('Service timed out') --> 342 raise GeocoderServiceError(message) 343 344 if hasattr(page, 'getcode'):

GeocoderServiceError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)

1
Are you behind some kind of proxy? Because "maps.google.co.uk" is certainly not using a self signed certificate and yet you get error message "certificate verify failed: self signed certificate in certificate chain"Patrick Mevzek
I searched for how to check if I am behind a proxy => In Google Chrome browser go to advanced settings -> Network -> Proxies and check if any of the options are ticked. They were all unticked. Does this answer your question? Or, is there another way to find if I am behind some proxy? Thanksaz_aza
First check from your Python code to which IP addresses maps.google.co.uk does resolve, and if they are from Google really. Then your Python code may be using a proxy even if Chrome is not using one. Also did you try with any other name? Does the result change if you change the network to which your computer is attached to?Patrick Mevzek

1 Answers

1
votes

Take a look at the following link: here

I was able to get it working by running the second command on that page:

open /Applications/Python\ 3.7/Install\ Certificates.command