3

I got the following error when installing the Google Cloud SDK on my Windows 10 computer:

ERROR: gcloud failed to load: 'ascii' codec can't decode byte 0xe1 in position 13: ordinal not in range(128)
    gcloud_main = _import_gcloud_main()
    import googlecloudsdk.gcloud_main
    from googlecloudsdk.calliope import cli
    from googlecloudsdk.calliope import backend
    from googlecloudsdk.calliope import parser_extensions
    from googlecloudsdk.core.updater import update_manager
    from googlecloudsdk.core.updater import installers
    from googlecloudsdk.core.credentials import store
    from googlecloudsdk.core.credentials import creds
    from googlecloudsdk.core.credentials import devshell as c_devshell
    from oauth2client import client
    from oauth2client import crypt
    from oauth2client import _openssl_crypt
    from OpenSSL import crypto
    from OpenSSL import crypto, SSL
    from cryptography import x509
    from cryptography.x509.base import (
    from cryptography.x509.extensions import Extension, ExtensionType
    from asn1crypto.keys import PublicKeyInfo
    from ._elliptic_curve import (
    from ._int import inverse_mod
    from ._perf._big_num_ctypes import libcrypto
    libcrypto_path = find_library('crypto')
    fname = os.path.join(directory, name)
    result_path = result_path + p_path
This usually indicates corruption in your gcloud installation or problems with your Python interpreter.
Please verify that the following is the path to a working Python 2.7 executable:
    C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\python.exe
If it is not, please set the CLOUDSDK_PYTHON environment variable to point to a working Python 2.7 executable.
If you are still experiencing problems, please reinstall the Cloud SDK using the instructions here:
    https://cloud.google.com/sdk/
Traceback (most recent call last):
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\\bin\bootstrapping\install.py", line 12, in <module>
    import bootstrapping
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\bin\bootstrapping\bootstrapping.py", line 44, in <module>
    from googlecloudsdk.core.credentials import store as c_store
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\lib\googlecloudsdk\core\credentials\store.py", line 35, in <module>
    from googlecloudsdk.core.credentials import creds
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\lib\googlecloudsdk\core\credentials\creds.py", line 34, in <module>
    from googlecloudsdk.core.credentials import devshell as c_devshell
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\lib\googlecloudsdk\core\credentials\devshell.py", line 30, in <module>
    from oauth2client import client
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\lib\third_party\oauth2client\client.py", line 51, in <module>
    from oauth2client import crypt
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\lib\third_party\oauth2client\crypt.py", line 45, in <module>
    from oauth2client import _openssl_crypt
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\lib\third_party\oauth2client\_openssl_crypt.py", line 16, in <module>
    from OpenSSL import crypto
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
    from OpenSSL import crypto, SSL
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\site-packages\OpenSSL\crypto.py", line 12, in <module>
    from cryptography import x509
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\site-packages\cryptography\x509\__init__.py", line 9, in <module>
    from cryptography.x509.base import (
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\site-packages\cryptography\x509\base.py", line 16, in <module>
    from cryptography.x509.extensions import Extension, ExtensionType
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\site-packages\cryptography\x509\extensions.py", line 13, in <module>
    from asn1crypto.keys import PublicKeyInfo
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\site-packages\asn1crypto\keys.py", line 22, in <module>
    from ._elliptic_curve import (
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\site-packages\asn1crypto\_elliptic_curve.py", line 51, in <module>
    from ._int import inverse_mod
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\site-packages\asn1crypto\_int.py", line 56, in <module>
    from ._perf._big_num_ctypes import libcrypto
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\site-packages\asn1crypto\_perf\_big_num_ctypes.py", line 31, in <module>
    libcrypto_path = find_library('crypto')
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\ctypes\util.py", line 53, in find_library
    fname = os.path.join(directory, name)
  File "C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\lib\ntpath.py", line 85, in join
    result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe1 in position 13: ordinal not in range(128)
Failed to install.

I have tried redownloading the installer, I run it with admin rights and I have choosen an install folder without any non-ascii characters or spaces.

I also verified that the installer set up the python successfully, more specifically I have Python version 2.7.13 at C:\AndroidSdk\CloudSdk\google-cloud-sdk\platform\bundledpython\python.exe

I also have tried to set the CLOUDSDK_PYTHON variable without success.

Note: I saw this question, but I have a different version (213.0.0) of the cloud-sdk and I didn't find the mentioned part in my code, so I don't think this is a duplicate question.

EDIT 1:

My ntpath.py line 63-90:

def join(path, *paths):
    """Join two or more pathname components, inserting "\\" as needed."""
    result_drive, result_path = splitdrive(path)
    for p in paths:
        p_drive, p_path = splitdrive(p)
        if p_path and p_path[0] in '\\/':
            # Second path is absolute
            if p_drive or not result_drive:
                result_drive = p_drive
            result_path = p_path
            continue
        elif p_drive and p_drive != result_drive:
            if p_drive.lower() != result_drive.lower():
                # Different drives => ignore the first path entirely
                result_drive = p_drive
                result_path = p_path
                continue
            # Same drive in different case
            result_drive = p_drive
        # Second path is relative to the first
        if result_path and result_path[-1] not in '\\/':
            result_path = result_path + '\\'
        result_path = result_path + p_path   #85
    ## add separator between UNC and non-absolute path
    if (result_path and result_path[0] not in '\\/' and
        result_drive and result_drive[-1:] != ':'):
        return result_drive + sep + result_path
    return result_drive + result_path

EDIT 2:

Thank you for your suggestions I have checked these SO questions and answers also, but I could not find a solution:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 13: ordinal not in range(128)

Bitbucket Pipelines: gcloud crashed (UnicodeDecodeError)

Note that I do not have any non-ascii characters in gcloud path, I have checked it with the following command: gci -recurse . | where {$_.Name -match "[^\u0000-\u007F]"}

Any other ideas how to fix?

serv-inc
  • 35,772
  • 9
  • 166
  • 188
bendaf
  • 2,981
  • 5
  • 27
  • 62
  • Haven't tried this. What does it say in `ntpath.py` line 85 anyway? [**Did you see this**](https://stackoverflow.com/q/18649512/129130)? Maybe some generic approaches you can test quickly: **1)** Test install on a clean virtual? **2)** Do a test install with a freshly created local admin user? **3)** Do you have access to an English machine? – Stein Åsmul Aug 21 '18 at 23:05
  • I have added the relevant part from my ntpath.py. I don't have to much free space or English machince currently, but I will try those steps if I won't be able to solve the problem an another way. – bendaf Aug 22 '18 at 09:10
  • Possible duplicate of [Bitbucket Pipelines: gcloud crashed (UnicodeDecodeError)](https://stackoverflow.com/questions/51620611/bitbucket-pipelines-gcloud-crashed-unicodedecodeerror) – snakecharmerb Aug 22 '18 at 20:18
  • Thanks you for the suggestion, I have editied my question where it is different from the other. – bendaf Aug 23 '18 at 07:54
  • Hi bendaf, if you reply to people, use the `@` sign to notify them. Example: @Stein (do the same for mr snake if you think he would like to see the reply) – serv-inc Aug 23 '18 at 08:23

4 Answers4

2

Just a list of things to try:

  1. install Python from https://www.python.org/downloads/release/python-2715/. Remember the location of the python binary. Set that as CLOUDSDK_PYTHON

  2. Show the printout with the variable set.

  3. Ensure that the variable is really set.

  4. In C:\ (or C:\AndroidSdk, but optimally C:\): Run the gci command in https://superuser.com/questions/237533/find-files-with-non-ascii-characters-in-filenames-in-windows-xp, show the output. Or run the python program from that same question.

  5. would be found by 4., but the 13th character seems to be the \. Try to re-create the directory, giving the AndroidSDK a shorter/longer name, see if it still is the 13th character

serv-inc
  • 35,772
  • 9
  • 166
  • 188
  • 1
    The external python download seem to solved the problem. (It still displays error message about some ascii character in different files, but installs and runs succesfully). Thank you @serv-inc! (I'm not sure this notification-thing works in SO also, I do get notifications regardless if I'm mentioned in them or not) – bendaf Aug 23 '18 at 10:32
  • You're welcome @bendaf. SO tries to smartly guess whom you are replying to. If you want to make sure, mention them explicitly. – serv-inc Aug 23 '18 at 13:10
1

I just had the same problem and it took me a while to solve it, so here's my findings for posterity:

I had the npm package windows-build-tools installed (using npm install --global windows-build-tools), and that package apparently came with a separate Python installation in C:\Users\[my user]\.windows-build-tools which I had forgotten about. That folder was also in my PATH.

Now unfortunately my Windows user name contains non-ASCII characters. As far as I'm aware, there is no way for me to change this, as my user is tied to a MS account that my employer manages.

Despite me installing the SDK in a unproblematic location (D:\CloudSDK) and setting CLOUDSDK_PYTHON to another Python 2.7.15 installation, I kept getting the error described in the question, until I removed the windows build tools python installation plus every other trace of any previous Python installation I found and re-installed 2.7.15 cleanly. I then retried the Cloud SDK installation without the bundled Python and used my clean new one from PATH, which solved the problem.

Maybe this helps someone.

Grüse
  • 1,096
  • 2
  • 11
  • 24
0

Same problem with non-ascii chars. I edited the cloud_env.bat in the install root folder (mine is C:\prg\GCP) and REMOVED appending the %PATH% (see below) - problem solved for install.

I also had to add this manual to the PATH after install: C:\prg\GCP\google-cloud-sdk\bin;C:\prg\GCP\google-cloud-sdk\platform\bundledpython\;

AND update the USERPROFILE=C:\prg\GCP (mine contained non-ascii).

cloud_env.bat

ECHO OFF
CLS
REM SET PATH=C:\prg\GCP\google-cloud-sdk\bin;%PATH%;
SET PATH=C:\prg\GCP\google-cloud-sdk\bin;
cd C:\prg\GCP
ECHO Welcome to the Google Cloud SDK! Run "gcloud -h" to get the list of available commands.
ECHO ---
ECHO ON`
Cato
  • 1
  • 2
0

For me, window10,

it happen because the python 2.7 paths get found before the python 3.7,

I simply delete 2.7 PATH

and SET CLOUDSDK_PYTHON point to the 3.7 paths and it works.

Luk Aron
  • 1,235
  • 11
  • 34