Google Cloud SDK安装错误:UnicodeDecodeError:'ascii'编解码器无法解码位置197的字节0xe2:序数不在范围内(128)

Google Cloud SDK安装错误:UnicodeDecodeError:'ascii'编解码器无法解码位置197的字节0xe2:序数不在范围内(128)

问题描述:

我的计算机(MAC)上的Google Cloud SDK安装过程失败,并给了我以下堆栈跟踪信息.

Google Cloud SDK installation process is failing on my machine(MAC) and giving me following stack trace.

Traceback (most recent call last):
  File "/Users/ttn/Desktop/google-cloud-sdk/bin/bootstrapping/install.py", line 218, in <module>
    main()
  File "/Users/ttn/Desktop/google-cloud-sdk/bin/bootstrapping/install.py", line 203, in main
    sdk_root=bootstrapping.SDK_ROOT,
  File "/Users/ttn/Desktop/google-cloud-sdk/lib/googlecloudsdk/core/platforms_install.py", line 452, in UpdateRC
    completion_update, path_update, rc_path, sdk_root, host_os).Update()
  File "/Users/ttn/Desktop/google-cloud-sdk/lib/googlecloudsdk/core/platforms_install.py", line 214, in Update
    self.path, rc_contents, source_line=self._GetSourceLine())
  File "/Users/ttn/Desktop/google-cloud-sdk/lib/googlecloudsdk/core/platforms_install.py", line 167, in _GetRcContents
    filtered_contents=filtered_contents, line=line)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 197: ordinal not in range(128)

以下是一些详细信息:

系统的默认python版本

System's default python version

python -V
Python 3.6.1 :: Anaconda custom (x86_64)

用于Cloud SDK的Python版本.

Python version for Cloud SDK.

echo $CLOUDSDK_PYTHON
/usr/bin/python2.7

检查gcloud命令

gcloud
-bash: gcloud: command not found

注意:这个问题看似重复,但我尝试了门户网站上提供的解决方案很少,但对我却无济于事.

Note: This question might seem as duplicate, but i tried few solution available on portal but nothing worked for me.

下面有一个公开的请求请求来解决此问题,此链接已解决.问题是其中一个文件包含非ASCII字符,这会导致Google Cloud SDK安装程序失败. Python 2.7中的open()函数不允许指定的编码.

There is an open pull request to address this issue linked below that fixes the issue. The issue was that one of the files contain non-ASCII characters which causes the the Google Cloud SDK installer to fail. The open() function in Python 2.7 doesn't allow for a specified encoding.

修复:
所有带有open()的引用都应替换为io.open(..., encoding='utf-8').再次检查拉动请求以查看那些更改.

Fix:
All references with open() should be replaced with io.open(..., encoding='utf-8'). Once again check the pull request to see those changes.

资源:
- https://github.com/google-cloud -sdk/google-cloud-sdk/pull/2/files

Resources:
- https://github.com/google-cloud-sdk/google-cloud-sdk/pull/2/files