使用 Windows SSL 错误安装 Google Cloud SDK

Installing Google Cloud SDK using Windows SSL error

我正在尝试在我公司的计算机上安装 Google Cloud SDK,但它似乎无法正常工作。我认为这与防火墙有关,但我无法弄清楚。

这是错误信息。你有什么线索吗?

我尝试禁用 VPN,但没有用。另外,我是 运行 具有管理员权限的 .exe。

Output folder: C:\Program Files (x86)\Google\Cloud SDK
Downloading Google Cloud SDK core.
Extracting Google Cloud SDK core.
Create Google Cloud SDK bat file: C:\Program Files (x86)\Google\Cloud SDK\cloud_env.bat
Installing components.
Welcome to the Google Cloud SDK!
Beginning update. This process may take several minutes.
This will install all the core command line tools necessary for working with
the Google Cloud Platform.
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\urllib3\contrib\pyopenssl.py", line 488, in wrap_socket
    cnx.do_handshake()
  File "C:\Users\ADMINA~1\AppData\Local\Temp\tmpil4t_39u\python\lib\OpenSSL\SSL.py", line 1894, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\Users\ADMINA~1\AppData\Local\Temp\tmpil4t_39u\python\lib\OpenSSL\SSL.py", line 1632, in _raise_ssl_error
    _raise_current_error()
  File "C:\Users\ADMINA~1\AppData\Local\Temp\tmpil4t_39u\python\lib\OpenSSL\_util.py", line 57, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\urllib3\connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\urllib3\connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\urllib3\connectionpool.py", line 976, in _validate_conn
    conn.connect()
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\urllib3\connection.py", line 361, in connect
    self.sock = ssl_wrap_socket(
  File "C:\Program Files (x86)\Google\Cloud SDK\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 "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\urllib3\contrib\pyopenssl.py", line 494, in wrap_socket
    raise ssl.SSLError("bad handshake: %r" % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\urllib3\connectionpool.py", line 724, in urlopen
    retries = retries.increment(
  File "C:\Program Files (x86)\Google\Cloud SDK\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(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\bootstrapping\install.py", line 308, in <module>
    main()
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\bootstrapping\install.py", line 285, in main
    Install(pargs.override_components, pargs.additional_components)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\bootstrapping\install.py", line 155, in Install
    InstallOrUpdateComponents(to_install, update=update)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\bootstrapping\install.py", line 197, in InstallOrUpdateComponents
    _CLI.Execute(
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\calliope\cli.py", line 1013, in Execute
    self._HandleAllErrors(exc, command_path_string, specified_arg_names)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\calliope\cli.py", line 1050, in _HandleAllErrors
    exceptions.HandleError(exc, command_path_string, self.__known_error_handler)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\calliope\exceptions.py", line 547, in HandleError
    core_exceptions.reraise(exc)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\exceptions.py", line 146, in reraise
    six.reraise(type(exc_value), exc_value, tb)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\six\__init__.py", line 693, in reraise
    raise value
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\calliope\cli.py", line 987, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\calliope\backend.py", line 809, in Run
    resources = command_instance.Run(args)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\surface\components\update.py", line 124, in Run
    update_manager.Update(
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\updater\update_manager.py", line 946, in Update
    install_state, diff = self._GetStateAndDiff(
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\updater\update_manager.py", line 652, in _GetStateAndDiff
    latest_snapshot = self._GetLatestSnapshot(version=version,
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\updater\update_manager.py", line 635, in _GetLatestSnapshot
    return snapshots.ComponentSnapshot.FromURLs(
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\updater\snapshots.py", line 175, in FromURLs
    data = [
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\updater\snapshots.py", line 176, in <listcomp>
    (ComponentSnapshot._DictFromURL(
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\updater\snapshots.py", line 200, in _DictFromURL
    response = installers.MakeRequest(url, command_path)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\updater\installers.py", line 114, in MakeRequest
    return _RawRequest(url, headers=headers, timeout=timeout)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\updater\installers.py", line 162, in _RawRequest
    return retryer.RetryOnException(
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\util\retry.py", line 201, in RetryOnException
    exceptions.reraise(exc_info[1], tb=exc_info[2])
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\exceptions.py", line 146, in reraise
    six.reraise(type(exc_value), exc_value, tb)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\six\__init__.py", line 693, in reraise
    raise value
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\util\retry.py", line 182, in TryFunc
    return func(*args, **kwargs), None
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\updater\installers.py", line 192, in _ExecuteRequestAndRaiseExceptions
    response = requests_session.get(
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\requests\sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\transport.py", line 251, in WrappedRequest
    response = orig_request(*modified_args, **modified_kwargs)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\core\requests.py", line 216, in WrappedRequest
    return orig_request_method(*args, **kwargs)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\third_party\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Program Files (x86)\Google\Cloud SDK\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(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])"

不正确的地铁格式:activa: 安装失败。)))

SLL 错误

基本上这至少有 4 个不同的原因:

  • 对您正在访问的资源使用自签名证书。
  • 贵公司拦截并检查 HTTPS 流量,从而在证书链的顶部添加自己的证书....
  • 您的操作系统不知道用于设置证书的证书颁发机构。
  • 您的编程语言或框架不知道用于设置证书的证书颁发机构。

解决方案 1:证书

我试图沿着捕获证书的道路前进,并尝试将其强制加载到我执行安装的环境中......

那是个兔子洞。但是如果你让它工作,请让我知道,因为我很感兴趣...

解决方案 2:停用验证

最后,对我来说最简单的解决方案是确保禁用内部验证。我在调试模式下执行了几分钟的代码,找到了我想要的文件... sessions.py

找到它,如果你的安装路径是:

C:\ProgramFiles\Google\SDK\

文件位于:

C:\ProgramFiles\Google\SDK\google-cloud-sdk\lib\third_party\requests\sessions.py

在该文件的第 523-525 行中,您会找到 verify 罪魁祸首,您只需将其更新为 False :

        settings = self.merge_environment_settings(
            prep.url, proxies, stream, verify, cert
        )

只需将其更改为:

        settings = self.merge_environment_settings(
            prep.url, proxies, stream, False, cert
        )

并保存。之后只需在提示符下执行安装命令。我正在使用 Anaconda 提示符,但任何其他有权访问 python 的人都应该这样做。

$ cd C:\ProgramFiles\Google\SDK\google-cloud-sdk
$ install

这不是最优雅的解决方案,因为证书不起作用,但它可以完成工作。

注:

你会在安装过程中收到一些警告,建议你启用证书验证....如下所示:

#= Installing: gcloud cli dependencies                      =#
#C:\ProgramFiles\Google\SDK\google-cloud-sdk\lib\third_party\urllib3\connectionpool.py:979: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dl.google.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  warnings.warn(
============================================================#