Looks like some of my system setting is messed up. I am on MAC OS and have no issues using browser to go to any https site or curl to below failing site I am getting SSLError using my 3 line code below (error below)
MaxRetryError: HTTPSConnectionPool(host='maps.googleapis.com', port=443): Max retries exceeded with url: /maps/api/geocode/json?address=denver&key=AIxxxxxxxxx (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)')))
I have tried this on both python2.7.10 and python3.7.0
Code that gives error:
$ ipython
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.0.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:import googlemaps
gm = googlemaps.Client(key='AIxxxxxxxxxxxxxx')
geocode_result = gm.geocode('denver')[0]::
:--
TransportError: HTTPSConnectionPool(host='maps.googleapis.com', port=443): Max retries exceeded with url: /maps/api/geocode/json?address=denver&key=AIxxxxxxxxxxxxxx (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)')))
$ python
Python 2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import googlemaps
>>> gm = googlemaps.Client(key='AIxxxxxxxxxxxxxx')
>>> geocode_result = gm.geocode('denver')[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/googlemaps/client.py", line 365, in wrapper
result = func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/googlemaps/geocoding.py", line 68, in geocode
return client._request("/maps/api/geocode/json", params).get("results", [])
File "/Library/Python/2.7/site-packages/googlemaps/client.py", line 240, in _request
raise googlemaps.exceptions.TransportError(e)
googlemaps.exceptions.TransportError: HTTPSConnectionPool(host='maps.googleapis.com', port=443): Max retries exceeded with url: /maps/api/geocode/json?address=denver&key=AIxxxxxxxxxxxxxx (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
>>>
I am new so please don't be harsh, it may be simple thing and thats why I have been searching online for last 4 hours, and seems like your server is not sending a TLS cert chain
may be a cause, but I do not know the actual cause or the fix to that
For other people upgrading pyopenssl fixed the issue (my pyopenssl is latest at 19.0.0), most were using request and used verify = False
to fix
Also if there's any other way to test if other calls are working, please let me know
Earlier I was also getting SSLError with pip install
but that is fixed by combination of upgrading pip to latest version and added trusted host to pip.conf
I couldn't find a similar issue with "solution", last one was close but for specific site only: https://github.com/kennethreitz/requests/issues/4381 https://github.com/kennethreitz/requests/issues/4247 Python Requests getting SSLerror
===================//Update based on comment:
Several searches said fix is to run /Applications/Python\ 3.6/Install\ Certificates.command
I was on 3.7.0 but /Applications/Python\ 3.7/Install\ Certificates.command
did not existed
I couldn't figure out the right Install Certificate command, so I upgraded to 3.7.3 and there wasn't any Install Certificate
command along the installation, so finally I downgraded to 3.6.0 and ran the above command
$ python3 --version
Python 3.6.0
$
$ /Applications/Python\ 3.6/Install\ Certificates.command
-- pip install --upgrade certifi
Collecting certifi
Downloading https://files.pythonhosted.org/packages/69/1b/b853c7a9d4f6a6d00749e94eb6f3a041e342a885b87340b79c1ef73e3a78/certifi-2019.6.16-py2.py3-none-any.whl (157kB)
100% |████████████████████████████████| 163kB 1.0MB/s
Installing collected packages: certifi
Successfully installed certifi-2019.6.16
You are using pip version 9.0.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
-- removing any existing file or link
-- creating symlink to certifi certificate bundle
-- setting permissions
-- update complete
$
$ python3
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import googlemaps
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'googlemaps'
I am not sure if pip3 and pip are different but regardless I tried $ pip3 install googlemaps
because I see googlemaps is present in pip list
but not in pip3 list
$ pip list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Package Version
-------------------------------------- ---------
.
.
googlemaps 3.0.2
$ pip3 list
.
.
certifi (2019.6.16)
pip (9.0.1)
$ pip3 install --ignore-installed googlemaps
Collecting googlemaps
Downloading https://files.pythonhosted.org/packages/5a/3d/13b4230f3c1b8a586cdc8d8179f3c6af771c11247f8de9c166d1ab37f51d/googlemaps-3.0.2.tar.gz
Complete output from command python setup.py egg_info:
Download error on https://pypi.python.org/simple/requests/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- Some packages may not be found!
Couldn't find index page for 'requests' (maybe misspelled?)
Download error on https://pypi.python.org/simple/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- Some packages may not be found!
No local packages or working download links found for requests<3.0,>=2.11.1
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/83/lbn35h2j2491r5wy78tpyky40000gn/T/pip-build-sknne9mv/googlemaps/setup.py", line 40, in <module>
'Topic :: Internet',
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 315, in __init__
self.fetch_build_eggs(attrs['setup_requires'])
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 361, in fetch_build_eggs
replace_conflicting=True,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 850, in resolve
dist = best[req.key] = env.best_match(req, ws, installer)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1122, in best_match
return self.obtain(req, installer)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1134, in obtain
return installer(requirement)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 429, in fetch_build_egg
return cmd.easy_install(req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 659, in easy_install
raise DistutilsError(msg)
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('requests<3.0,>=2.11.1')
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/83/lbn35h2j2491r5wy78tpyky40000gn/T/pip-build-sknne9mv/googlemaps/
You are using pip version 9.0.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$
Also looks I still have python 3.7.3 as my ipython opens that version:
$ ipython
Python 3.7.3 (default, Mar 27 2019, 09:23:39)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import googlemaps
In [2]:
Sorry if this is too long but looks like I am missing something, I have spend over 16 hours on this and still stuck on the same issue.