如何解决安装 gcloud 时出现 `CERTIFICATE_VERIFY_FAILED` 错误?

问题描述 投票:0回答:6

我尝试在 MacO 中安装 gcloud 但失败。我尝试了两个 python 版本 3.7.4 和 3.9.1,但都有相同的问题。如何安装

gcloud
?我还需要其他依赖吗?

$ python --version
Python 3.9.1

$ sh install.sh --screen-reader=true
Welcome to the Google Cloud SDK!

To help improve the quality of this product, we collect anonymized usage data
and anonymized stacktraces when crashes are encountered; additional information
is available at <https://cloud.google.com/sdk/usage-statistics>. This data is
handled in accordance with our privacy policy
<https://cloud.google.com/terms/cloud-privacy-notice>. You may choose to opt in this
collection now (by choosing 'Y' at the below prompt), or at any time in the
future by running the following command:

    gcloud config set disable_usage_reporting false

Do you want to help improve the Google Cloud SDK (y/N)?  y

Traceback (most recent call last):
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/urllib3/connectionpool.py", line 667, in urlopen
    self._prepare_proxy(conn)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/urllib3/connectionpool.py", line 930, in _prepare_proxy
    conn.connect()
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/urllib3/connection.py", line 361, in connect
    self.sock = ssl_wrap_socket(
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/urllib3/util/ssl_.py", line 382, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/Users/joey/.pyenv/versions/3.9.1/lib/python3.9/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Users/joey/.pyenv/versions/3.9.1/lib/python3.9/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Users/joey/.pyenv/versions/3.9.1/lib/python3.9/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/urllib3/connectionpool.py", line 724, in urlopen
    retries = retries.increment(
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dl.google.com', port=443): Max retries exceeded with url: /dl/cloudsdk/channels/rapid/components-2.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/joey/Downloads/google-cloud-sdk/bin/bootstrapping/install.py", line 232, in <module>
    main()
  File "/Users/joey/Downloads/google-cloud-sdk/bin/bootstrapping/install.py", line 210, in main
    Install(pargs.override_components, pargs.additional_components)
  File "/Users/joey/Downloads/google-cloud-sdk/bin/bootstrapping/install.py", line 151, in Install
    _CLI.Execute(['--quiet', 'components', 'list'])
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 1008, in Execute
    self._HandleAllErrors(exc, command_path_string, specified_arg_names)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 1045, in _HandleAllErrors
    exceptions.HandleError(exc, command_path_string, self.__known_error_handler)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/calliope/exceptions.py", line 551, in HandleError
    core_exceptions.reraise(exc)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/exceptions.py", line 146, in reraise
    six.reraise(type(exc_value), exc_value, tb)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/six/__init__.py", line 693, in reraise
    raise value
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 982, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 809, in Run
    resources = command_instance.Run(args)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/surface/components/list.py", line 102, in Run
    result = update_manager.List(show_hidden=args.show_hidden,
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py", line 714, in List
    to_print, current_version, latest_version = self._GetPrintListWithDiff()
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py", line 750, in _GetPrintListWithDiff
    _, diff = self._GetStateAndDiff(command_path='components.list')
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py", line 641, in _GetStateAndDiff
    latest_snapshot = self._GetLatestSnapshot(version=version,
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py", line 624, in _GetLatestSnapshot
    return snapshots.ComponentSnapshot.FromURLs(
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/snapshots.py", line 178, in FromURLs
    data = [
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/snapshots.py", line 179, in <listcomp>
    (ComponentSnapshot._DictFromURL(
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/snapshots.py", line 204, in _DictFromURL
    response = installers.MakeRequestViaRequests(url, command_path)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/installers.py", line 203, in MakeRequestViaRequests
    return _RawRequestViaRequests(url, headers=headers, timeout=timeout)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/installers.py", line 251, in _RawRequestViaRequests
    return retryer.RetryOnException(
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 195, in RetryOnException
    exceptions.reraise(exc_info[1], tb=exc_info[2])
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/exceptions.py", line 146, in reraise
    six.reraise(type(exc_value), exc_value, tb)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/six/__init__.py", line 693, in reraise
    raise value
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 176, in TryFunc
    return func(*args, **kwargs), None
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/installers.py", line 281, in _ExecuteRequestAndRaiseExceptions
    response = requests_session.get(
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/transport.py", line 243, in WrappedRequest
    response = orig_request(*modified_args, **modified_kwargs)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/requests.py", line 198, in WrappedRequest
    return orig_request_method(*args, **kwargs)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/Users/joey/Downloads/google-cloud-sdk/lib/third_party/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='dl.google.com', port=443): Max retries exceeded with url: /dl/cloudsdk/channels/rapid/components-2.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)')))
python ssl google-cloud-platform google-cloud-sdk
6个回答
15
投票

运行以下命令禁用 ssl 验证

gcloud config set auth/disable_ssl_validation  True

5
投票

将 export CLOUDSDK_PYTHON="/usr/bin/python3" 添加到我的 .zshrc (zshell 配置文件)解决了我的问题。我用的是Mac。

直到我将上述内容添加到我的个人资料中,这个问题并没有消失,但我也做了以下操作,不确定解决这个问题是否需要所有这些步骤:

  1. https://www.python.org/downloads/ 安装最新的 python 3。我用的是python 3.10.4。
  2. 通过转到应用程序文件夹运行 python 3.10 Install Certificates.command,然后运行 python 3.10 并运行“Install Certificates.command”。
  3. 在 /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/certifi/cacert.pem 中添加了我的公司证书

4
投票

这对我有用:

  1. 解压安装程序下载的 google-cloud-sdk.zip。
  2. 打开 google-cloud-sdk\lib hird_party 请求\session.py
  3. 将“self.verify = True”行更改为“self.verify = False”
  4. 如果是解压到的目录,请在根目录中运行install.bat。
  5. 利润

0
投票

导致此错误的可能原因有很多,代理配置就是其中之一,但正如您提到的,您没有为您的网络配置代理,因此原因可能是其他原因。为了验证此错误是否是由于代理而发生的,您可以尝试运行以下命令:

$ curl https://dl.google.com/

Output: <a href="https://www.google.com/chrome"> Found  </a>

如果您得到与上述输出不同的输出,则说明您使用了代理或门户。

您可以参考这个 stackoverflow thread,其中云支持用户通过提供可能导致此 SSL 错误的各种可能原因给出了答案,他还提供了解决此错误的解决方法。 如果安装了任何此类软件,请尝试禁用防病毒设置。


0
投票

如果这对在 Windows 上遇到此问题的任何人有用,我无法找到 Matt D 提到的

google-cloud-sdk.zip
文件,但是在安装失败后,我在以下位置找到了提取的文件:

C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk

使用此文件夹位置,我按照 Matt D 概述的步骤完成了安装。


0
投票

用于在 dl.google.com 上获取包含组件列表的初始 JSON 文件的底层第三方工具似乎并非旨在获取证书捆绑包,并且不使用本地证书存储。 Matt D 上面关于在sessions.py 文件中禁用 ssl.verify 的评论有助于找到问题和解决方案。

该库使用 urllib3,它使用 Certifi 证书捆绑包。如果您位于执行 SSL 解密的防火墙后面,则需要将证书链嵌入到 Certifi 模块 PEM 文件中。您需要提取 CA、根证书和中级证书并构建捆绑包。

openssl s_client -showcerts --verify 5 -servername dl.google.com -connect dl.google.com:443 2>null

这将在链中拉出最多 5 个证书。没有任何一家班轮能够获得全部 3 项证书。如果您在 Windows 中,则必须按 Ctrl+C 并手动将 ----BEGIN CERTIFICATE----- 复制到第三个证书的末尾。它已经是正确的顺序了。只需清理它,保存它,然后将其插入到文件顶部: .\google-cloud-sdk\lib hird_part

© www.soinside.com 2019 - 2024. All rights reserved.