2

私はこのチュートリアルに従っています: https://developers.google.com/storage/docs/gspythonlibraryで、バケットを一覧表示しようとしているときにいくつかのエラーが発生します。

gsutil をダウンロードして、次のような PYTHONPATH に追加しました。

/home/nicolasalvo/tools/gsutil/third_party/boto:/home/nicolasalvo/tools/gsutil

私も実行しました:

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

グローバル オブジェクトを使用する前に宣言しようとしましたが、役に立ちませんでした。

また、手動で修正することなく、Google が提供する Cloud Storage 用のライブラリを使用できるはずです。

私はPython 2.7.3を実行しています

どんな助けでも大歓迎です

4

2 に答える 2

6

これは私のために働いた:

import threading
from gslib.third_party.oauth2_plugin import oauth2_client
oauth2_client.token_exchange_lock = threading.Lock()
于 2014-01-07T13:20:20.393 に答える
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

はい、動作します!!

于 2014-03-14T03:48:43.577 に答える