获取SSLError证书验证失败

时间:2019-06-17 23:50:41

标签: python macos pip ssl-certificate

好像我的某些系统设置搞砸了。我在MAC OS上,使用浏览器转到任何https站点或卷曲到失败站点以下都没有问题 我在下面的3行代码中收到了SSLError(以下错误)

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)')))

我已经在python2.7.10和python3.7.0上都尝试过

出现错误的代码:

$ 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')],)",),))
>>>

我是新来的,所以请不要苛刻,这可能很简单,这就是为什么我最近4个小时一直在网上搜索,似乎your server is not sending a TLS cert chain可能是一个原因,但我不知道实际原因或解决方法

对于其他升级pyopenssl的人,此问题已解决(我的pyopenssl最新版本为19.0.0),大多数人使用请求并使用verify = False进行修复 另外,如果还有其他方法可以测试其他电话是否正常工作,请告诉我

以前我也通过pip install收到SSLError,但是通过将pip升级到最新版本并将受信任的主机添加到pip.conf来解决此问题

我找不到与“解决方案”类似的问题,上一个已经关闭,但仅针对特定站点: https://github.com/kennethreitz/requests/issues/4381 https://github.com/kennethreitz/requests/issues/4247 Python Requests getting SSLerror

=================== ///基于评论进行更新:

几个搜索结果表明,解决方法是运行/Applications/Python\ 3.6/Install\ Certificates.command 我当时在3.7.0上,但是/Applications/Python\ 3.7/Install\ Certificates.command不存在 我无法确定正确的“安装证书”命令,因此我升级到3.7.3,并且安装过程中没有任何Install Certificate命令,因此最终我降级到3.6.0并运行上述命令

$ 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'

我不确定pip3和pip是否不同,但是无论我尝试了$ pip3 install googlemaps是因为我看到pip list中都存在googlemaps,而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.
$

当我的ipython打开该版本时,看起来我仍然拥有python 3.7.3:

$ 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]:

很抱歉,如果这个时间太长,但看起来好像我缺少什么,我已经花了16个小时以上,仍然停留在同一问题上。

0 个答案:

没有答案