阅读背景:

无法安装谷歌云sdk:“没有获取组件”Windows7。

来源:互联网 

When I try to intall google cloud sdk the following error occurs:

当我尝试intall谷歌云sdk时,出现以下错误:

ERROR: (gcloud.components.update) Failed to fetch component listing from server. Check your network settings and try again. Google Cloud SDK installer will now exit. Press any key to continue . . .

错误:(gcloud.components.update)未能从服务器获取组件列表。检查你的网络设置,再试一次。谷歌云SDK安装程序现在退出。按任意键继续…

result = func(*args)   File "C:\python27_x64\lib\urllib2.py", line 1222, in https_open
return self.do_open(httplib.HTTPSConnection, req)   File "C:\python27_x64\lib\urllib2.py", line 1184, in do_open
raise URLError(err) urllib2.URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>

Any ideas?

什么好主意吗?

2 个解决方案

#1


3  

I was getting a similar error both on installation and on certain commands on another previously working installation. After poking around and adding some logs, it looks like SSL Cert Verification is failing for the component listing request from Google's servers:

我在安装时和以前安装时的某些命令上都有类似的错误。在查看并添加了一些日志之后,看来谷歌服务器的组件列表请求的SSL Cert验证失败了:

$ gcloud preview managed-instance-groups ...
You do not currently have this command group installed.  Using it requires the installation of components: [preview]
Could not fetch [https://dl.google.com/dl/cloudsdk/release/components-2.json]
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>
ERROR: (gcloud) Failed to fetch component listing from server. Check your network settings and try again.

To solve it (in a way that is almost certainly inadvisable), I disabled SSL Cert Validation for that single request. If you want to go down this path, modify MakeRequest() in

为了解决这个问题(以一种几乎肯定不可取的方式),我为这个请求禁用了SSL Cert验证。如果您想沿着这条路径走,请在其中修改MakeRequest()

./google-cloud-sdk/lib/googlecloudsdk/core/updater/installers.py:248

from:

来自:

return urllib2.urlopen(req, timeout=TIMEOUT_IN_SEC)

to:

:

return urllib2.urlopen(req, timeout=TIMEOUT_IN_SEC, context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))

(There's an issue opened for this at https://code.google.com/p/google-cloud-sdk/issues/detail?id=143.)

(在https://code.google.com/p/goog -cloud-sdk/issues es/detail?

UPDATE: 26/05/15

更新:26/05/15

In my case, this turned out to be a mismatch between my installed version of OpenSSL and the version of OpenSSL referenced by Python (this may have started happening after updating to [email protected]).

在我的例子中,这是我安装的OpenSSL版本和Python引用的OpenSSL版本之间的不匹配(这可能是在更新到[email protected]之后发生的)。

To resolve this, I updated my version of OpenSSL to the latest:

为了解决这个问题,我更新了我的OpenSSL版本:

brew update
brew upgrade openssl

Then I reinstalled Python referencing this updated version of OpenSSL:

然后,我重新安装了引用OpenSSL更新版本的Python:

brew uninstall python
brew install python --with-brewed-openssl

After this, I nuked by Google Cloud SDK install (because I was mucking around in there a bit to find a solution; you might not have to do this) and installed from scratch:

之后,我通过谷歌云SDK安装(因为我在那里花了一点时间寻找解决方案;您可能不需要这样做)并从头安装:

curl https://sdk.cloud.google.com | bash

And we're golden!

我们黄金!

For further reading on these OpenSSL issues with OS X, check out this article: https://hynek.me/articles/apple-openssl-verification-surprises/

有关OS X的OpenSSL问题的进一步阅读,请参阅本文:https://hynek.me/articles/apple- openssl-verification/

#2


0  

TL;DR

博士TL;

  1. Locate the cacerts.txt file used by google's scripts. Should be in <google-cloud-sdk>/lib/third_party/httplib2/cacerts.txt.
  2. 除定位。谷歌脚本使用的txt文件。应该在< google-cloud-sdk > / lib / third_party / httplib2 / cacerts.txt。
  3. Open https://dl.google.com in Firefox and export its certificate(s).
  4. 在Firefox中打开https://dl.google.com并导出它的证书。
  5. Copy the contents of the certificate(s) to the end of the cacerts.txt file.
  6. 将证书的内容复制到cacerts的末尾。txt文件。

You may also need to make sure your system's openssl version is the same version as the openssl that's used by python, as of jemartti's answer. I tried it and it wasn't enough. I don't know whether it's essential.

您可能还需要确保您的系统的openssl版本与python所使用的openssl相同,如jemartti的答案。我试过了,但还不够。我不知道这是否必要。


Steps taken to reach this solution

为达到这一解决办法而采取的步骤

After trying jemartti's answer to no avail, I used the --verbosity debug flag in order to trace the point of failure. The output was:

在尝试了jemartti的答案之后,我使用了—verbosity调试标志来跟踪失败点。输出结果是:

DEBUG: Could not fetch [https://dl.google.com/dl/cloudsdk/channels/rapid/components-v100.0.0.json] Traceback (most recent call last): File "/usr/local/google-cloud-sdk/lib/googlecloudsdk/core/updater/snapshots.py", line 186, in _DictFromURL response = installers.ComponentInstaller.MakeRequest(url, command_path) File "/usr/local/google-cloud-sdk/lib/googlecloudsdk/core/updater/installers.py", line 277, in MakeRequest return urlopen_with_cacerts.urlopen(req, timeout=TIMEOUT_IN_SEC) File "/usr/local/google-cloud-sdk/lib/googlecloudsdk/core/util/urlopen_with_cacerts.py", line 40, in urlopen return orig_urlopen(*args, **kwargs) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open response = self._open(req, data) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open '_open', req) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain result = func(*args) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open context=self._context) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open raise URLError(err) URLError:

调试:无法获取[https://dl.google.com/dl/cloudsdk/channels/rapid/components-v100.0.0.0.0.json] Traceback(最近一次调用):File "/usr/local/google-cloud- cloud-sdk/lib/googlecloudsdk/core/updater/快照。在_DictFromURL response = installers.ComponentInstaller中,第186行。MakeRequest(url,command_path)文件“/ usr /地方/ google-cloud-sdk / lib / googlecloudsdk /核心/更新/安装程序。py“,第277行,在MakeRequest返回urlopen_with_cacerts。urlopen(请求超时= TIMEOUT_IN_SEC)文件“/ usr /本地/ google-cloud-sdk / lib / googlecloudsdk / / util / urlopen_with_cacerts核心。第40行,urlopen返回orig_urlopen(*args, **kwargs)文件"/usr/本地/地窖/python/2.7.11/框架/python .framework/版本/2.7/lib/python2.7/ urllib2.7 /urllib2.py"打开(url,数据,超时)文件“/usr/本地/地窖/python/2.7.11/框架/python .framework/版本/2.7/lib/python2.7/urllib2.py”,第431行,open response = self。" tahoma ", " sans - serif "; mso - fareast - font - family:宋体;mso - bidi - font - family: " times new roman "; mso - bidi - theme - font: minor - bidi ' > < / span > < span在https_open context=self._context文件"/usr/local/Cellar/python/2.7.11/ framework/ python .framework/ version /2.7/lib/python2.7/urllib2.py"第1197行do_open raise URLError(err)

So I opened /usr/local/google-cloud-sdk/core/util/urlopen_with_cacerts.py and saw that it calls httplib2's urlopen method with a cafile argument obtained from httplib2.CA_CERTS. I added a line that prints that httplib2.CA_CERTS, of which output was:

所以我打开/usr/local/google-cloud-sdk / / util / urlopen_with_cacerts核心。然后,它调用httplib2的urlopen方法,并使用从httplib2. ca_certs获得的cafile参数。我添加了一行来打印httplib2。CA_CERTS,输出为:

/usr/local/google-cloud-sdk/lib/third_party/httplib2/cacerts.txt

/usr/local/google-cloud-sdk / lib / third_party httplib2 / cacerts.txt

Then, as described in this answer, this is why I did:

然后,正如在这个答案中所描述的,这就是我这样做的原因:

  1. Open the URL in Firefox and export the certificate(s).
  2. 打开Firefox中的URL并导出证书。
  3. Copy the contents of the certificate(s) to the end of the cacerts.txt file.
  4. 将证书的内容复制到cacerts的末尾。txt文件。

As a Mac user, I also used the one-liner described here (that for some reason yielded a different certificate than Firefox's certificate-export feature), in order to save the certificate(s) on my machine (replace exmple.com and example.crt as needed):

作为一个Mac用户,我还使用了这里描述的一行程序(出于某种原因,它产生了与Firefox的证书导出功能不同的证书),以便将证书保存在我的机器上(替换exmple.com和示例)。根据需要crt):

openssl x509 -in <(openssl s_client -connect example.com:443 -prexit 2>/dev/null) -out ~/example.crt

分享到: