2017-09-28 2 views
0

파이썬에서 프로그래밍하지 않았습니다. 나는 처음으로 그러한 코드를 본다. 내 파이썬 gsutil 파일 :UnicodeDecodeError : 'ascii'코덱은 9 진수 0xc2를 디코딩 할 수 없습니다. 서수가 범위 내에 없습니다 (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() 

내가 같이 명령 줄에서 실행 :

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) 

어떻게 그것을 해결하기 위해 : 그것은 나에게 오류를 제공

gsutil config 

?

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

이 문제와 관련된 일부 의견은 [이 스레드] (https://stackoverflow.com/questions/46471114/)에 게시됩니다. – Kamran

답변

0

당신이 python3이 조각을 실행한다고 가정하지만, 이것은 단지 python2입니다 : 오류를 제공 라인입니다.

이미 두 개의 호환되지 않는 python 버전이 있다는 것을 알고 있다고 생각하십니까?

+0

Google Cloud SDK가 설치되었습니다. 그리고 거기에 양동이를 만들어보십시오. 나는 이것을 위해'gsutil' 도구를 사용합니다. 그러나 내가 그것을 부르면 그것은 나를 오류로 만든다. –

+0

@JaySmith 터미널에서 'python --version' 명령을 실행하십시오. 파이썬 3.5.2와 같은 것을 제공한다면 파이썬 3을 사용하고있는 것입니다. 'gsutil' 도구를 실행하려면 python2가 필요합니다. – Sraw

관련 문제

 관련 문제