2013-12-17 6 views
2

이 튜토리얼의 내용은 https://developers.google.com/storage/docs/gspythonlibrary이고 버킷 목록을 표시하는 동안 몇 가지 오류가 발생합니다.Python을 사용하여 Google Cloud Storage 버킷을 나열하십시오.

/홈/nicolasalvo/도구/인 gsutil/THIRD_PARTY/BOTO :/홈/nicolasalvo/도구/인 gsutil

나는 내가 인 gsutil을 다운로드하고 다음과 같습니다 내 PYTHONPATH에 추가 한

또한 실행이 맞는지 :

pip install -U oauth2client 

내가 실행하는 데 노력하고있어 코드는 다음과 같습니다

import StringIO 
import os 
import shutil 
import tempfile 
import time 
from gslib.third_party.oauth2_plugin import oauth2_plugin 

import boto 

# URI scheme for Google Cloud Storage. 
GOOGLE_STORAGE = 'gs' 
# URI scheme for accessing local files. 
LOCAL_FILE = 'file' 

uri = boto.storage_uri('', GOOGLE_STORAGE) 
for bucket in uri.get_all_buckets(): 
    print bucket.name 

내가있어 첫 번째 오류는 다음과 같습니다

:

나는 변화를 수동으로 수정 한
File "<stdin>", line 1, in <module> 
File "/home/nicolasalvo/tools/gsutil/gslib/third_party/oauth2_plugin/oauth2_plugin.py", line 3, in <module> 
import oauth2_client 
File "/home/nicolasalvo/tools/gsutil/gslib/third_party/oauth2_plugin/oauth2_client.py", line 33, in <module> 
import socks 

이 : 지금 직면하고있어 오류가

import socks 

import httplib2.socks 

File "/home/nicolasalvo/tools/gsutil/third_party/boto/boto/connection.py", line 876, in _mexe 
request.authorize(connection=self) 
File "/home/nicolasalvo/tools/gsutil/third_party/boto/boto/connection.py", line 377, in authorize 
connection._auth_handler.add_auth(self, **kwargs) 
File "/home/nicolasalvo/tools/gsutil/gslib/third_party/oauth2_plugin/oauth2_plugin.py", line 22, in add_auth 
self.oauth2_client.GetAuthorizationHeader() 
File "/home/nicolasalvo/tools/gsutil/gslib/third_party/oauth2_plugin/oauth2_client.py", line 325, in GetAuthorizationHeader 
return 'Bearer %s' % self.GetAccessToken().token 
File "/home/nicolasalvo/tools/gsutil/gslib/third_party/oauth2_plugin/oauth2_client.py", line 288, in GetAccessToken 
token_exchange_lock.acquire() 
NameError: global name 'token_exchange_lock' is not defined 

전역 obj를 선언하려했습니다. 그것을 사용하기 전에 요법,하지만 도움이되지 않았습니다.

또한 수동 수정 없이도 Cloud Storage 용 Google 제공 라이브러리를 사용할 수 있어야합니다.

내가 파이썬 2.7.3

하고 있는데, 어떤 도움을 크게 이것은 나를 위해 일한

+0

[google-api-python-client] (https://code.google.com/p/google-api-python-client/)를 사용하지 않으려는 이유가 무엇인가요? – jterrace

+0

JSON API는 실험적으로 표시되었으므로 XML API가보다 안정적이지만 google-api-client를 사용해 보았지만 작동하지만 여전히 다른 API와 함께 문제를 해결하는 데 관심이 있습니다 .. – ROOTto

답변

6

를 감사 :

import threading 
from gslib.third_party.oauth2_plugin import oauth2_client 
oauth2_client.token_exchange_lock = threading.Lock() 
+0

나를 위해 Works for Ubuntu 13.10 –

4
import StringIO 
import os 
import shutil 
import tempfile 
import time 
import threading 
import boto 

from gslib.third_party.oauth2_plugin import oauth2_plugin 
from gslib.third_party.oauth2_plugin import oauth2_client 

oauth2_client.token_exchange_lock = threading.Lock() 

# URI scheme for Google Cloud Storage. 
GOOGLE_STORAGE = 'gs' 

# URI scheme for accessing local files. 
LOCAL_FILE = 'file' 

project_id = 'abc.com:abc' 

uri = boto.storage_uri('', GOOGLE_STORAGE) 

header_values = {"x-goog-project-id": project_id} 

for bucket in uri.get_all_buckets(headers=header_values): 
    print bucket.name 

예 그것은 작동!

관련 문제