2017-09-28 2 views
0

Ich habe nicht auf Python programmiert. Ich sehe diesen Code zum ersten Mal. Meine Python gsutil Datei:UnicodeDecodeError: 'Ascii' Codec kann Byte 0xc2 in Position 9 nicht dekodieren: Ordnungszahl nicht im Bereich (128)

#!/usr/bin/env python 
# 
# Copyright 2013 Google Inc. All Rights Reserved. 
# 

"""A convenience wrapper for starting gsutil.""" 

import os 
import sys 


import bootstrapping 
from googlecloudsdk.core import config 
from googlecloudsdk.core import metrics 
from googlecloudsdk.core import properties 
from googlecloudsdk.core.credentials import gce as c_gce 


def _MaybeAddBotoOption(args, section, name, value): 
    if value is None: 
    return 
    args.append('-o') 
    args.append('{section}:{name}={value}'.format(
     section=section, name=name, value=value)) 


def main(): 
    """Launches gsutil.""" 

    project, account = bootstrapping.GetActiveProjectAndAccount() 
    pass_credentials = (
     properties.VALUES.core.pass_credentials_to_gsutil.GetBool() and 
     not properties.VALUES.auth.disable_credentials.GetBool()) 

    if pass_credentials and account not in c_gce.Metadata().Accounts(): 
    gsutil_path = config.Paths().LegacyCredentialsGSUtilPath(account) 

    # Allow gsutil to only check for the '1' string value, as is done 
    # with regard to the 'CLOUDSDK_WRAPPER' environment variable. 
    os.environ['CLOUDSDK_CORE_PASS_CREDENTIALS_TO_GSUTIL'] = '1' 

    boto_config = os.environ.get('BOTO_CONFIG', '') 
    boto_path = os.environ.get('BOTO_PATH', '') 

    # We construct a BOTO_PATH that tacks the refresh token config 
    # on the end. 
    if boto_config: 
     boto_path = os.pathsep.join([boto_config, gsutil_path]) 
    elif boto_path: 
     boto_path = os.pathsep.join([boto_path, gsutil_path]) 
    else: 
     path_parts = ['/etc/boto.cfg', 
        os.path.expanduser(os.path.join('~', '.boto')), 
        gsutil_path] 
     boto_path = os.pathsep.join(path_parts) 

    if 'BOTO_CONFIG' in os.environ: 
     del os.environ['BOTO_CONFIG'] 
    os.environ['BOTO_PATH'] = boto_path 

    # Tell gsutil whether gcloud analytics collection is enabled. 
    os.environ['GA_CID'] = metrics.GetCIDIfMetricsEnabled() 

    args = [] 

    _MaybeAddBotoOption(args, 'GSUtil', 'default_project_id', project) 
    if pass_credentials and account in c_gce.Metadata().Accounts(): 
    # Tell gsutil to look for GCE service accounts. 
    _MaybeAddBotoOption(args, 'GoogleCompute', 'service_account', 'default') 

    proxy_params = properties.VALUES.proxy 
    proxy_address = proxy_params.address.Get() 
    if proxy_address: 
    _MaybeAddBotoOption(args, 'Boto', 'proxy', proxy_address) 
    _MaybeAddBotoOption(args, 'Boto', 'proxy_port', proxy_params.port.Get()) 
    _MaybeAddBotoOption(args, 'Boto', 'proxy_rdns', proxy_params.rdns.GetBool()) 
    _MaybeAddBotoOption(args, 'Boto', 'proxy_user', proxy_params.username.Get()) 
    _MaybeAddBotoOption(args, 'Boto', 'proxy_pass', proxy_params.password.Get()) 
    disable_ssl = properties.VALUES.auth.disable_ssl_validation.GetBool() 
    _MaybeAddBotoOption(args, 'Boto', 'https_validate_certificates', 
         None if disable_ssl is None else not disable_ssl) 
    _MaybeAddBotoOption(args, 'Boto', 'ca_certificates_file', 
         properties.VALUES.core.custom_ca_certs_file.Get()) 

    bootstrapping.ExecutePythonTool('platform/gsutil', 'gsutil', *args) 


if __name__ == '__main__': 
    version = bootstrapping.GetFileContents('platform/gsutil', 'VERSION') 
    bootstrapping.CommandStart('gsutil', version=version) 

    blacklist = { 
     'update': 'To update, run: gcloud components update', 
    } 

    bootstrapping.CheckForBlacklistedCommand(sys.argv, blacklist, warn=True, 
              die=True) 
    # Don't call bootstrapping.PreRunChecks because anonymous access is 
    # supported for some endpoints. gsutil will output the appropriate 
    # error message upon receiving an authentication error. 
    bootstrapping.CheckUpdates('gsutil') 
    main() 

Wenn ich es von der Kommandozeile ausgeführt wird:

gsutil config 

Es mir diesen Fehler gibt:

Traceback (most recent call last): 
    File "D:\Programs\Google\Cloud SDK\google-cloud-sdk\bin\..\bin\bootstrapping\g 
sutil.py", line 102, in <module> 
    main() 
    File "D:\Programs\Google\Cloud SDK\google-cloud-sdk\bin\..\bin\bootstrapping\g 
sutil.py", line 55, in main 
    boto_path = os.pathsep.join(path_parts) 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 9: ordinal 
not in range(128) 

Wie es zu beheben? Linie, die Fehler gibt, ist:

boto_path = os.pathsep.join(path_parts) 
+0

Einige Kommentare zu diesem Problem sind auf [this thread] (https://stackoverflow.com/questions/46471114/) veröffentlicht. – Kamran

Antwort

0

Ich nehme an, Sie laufen diese Schnipsel mit python3, aber das ist nur für python2.

Ich denke, Sie haben bereits gewusst, dass es zwei inkompatible Python-Versionen gibt, oder?

+0

Ich habe Google Cloud SDK installiert. Und versuchen Sie, Bucket dort zu erstellen. Ich benutze 'gsutil' Werkzeug dafür. Aber wenn ich es nenne, geht es mir falsch. –

+0

@JaySmith Führen Sie in Ihrem Terminal den Befehl 'python --version' aus. Wenn Sie etwas wie "Python 3.5.2" erhalten, verwenden Sie python3. Sie benötigen Python2, um das 'gsutil'-Tool auszuführen. – Sraw

Verwandte Themen