使用Python列出Google Cloud Storage存储桶

 九九九丶 发布于 2023-02-09 18:32

我正在关注本教程:https://developers.google.com/storage/docs/gspythonlibrary,并在尝试列出我的存储桶时遇到几个错误.

我已经下载了gsutil并将其添加到我的PYTHONPATH中,如下所示:

/家庭/ nicolasalvo /工具/ gsutil会/ THIRD_PARTY /博托:/家庭/ nicolasalvo /工具/ 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 "", line 1, in 
File "/home/nicolasalvo/tools/gsutil/gslib/third_party/oauth2_plugin/oauth2_plugin.py", line 3, in 
import oauth2_client
File "/home/nicolasalvo/tools/gsutil/gslib/third_party/oauth2_plugin/oauth2_client.py", line 33, in 
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提供的库存储,而无需手动修复.

我正在运行Python 2.7.3

任何帮助是极大的赞赏

1 个回答
  • 这对我有用:

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

    2023-02-09 18:35 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有