Boto 客户端库插件
此代码用于创建存储桶,但我无法
import boto
import time
# URI scheme for Cloud Storage.
GOOGLE_STORAGE = 'gs'
# URI scheme for accessing local files.
LOCAL_FILE = 'file'
now = time.time()
CATS_BUCKET = 'cats-%d' % now
DOGS_BUCKET = 'dogs-%d' % now
print(CATS_BUCKET)
print(DOGS_BUCKET)
for name in (CATS_BUCKET, DOGS_BUCKET):
# Instantiate a BucketStorageUri object.
uri = boto.storage_uri(name, GOOGLE_STORAGE)
# create bucket
try:
uri.create_bucket()
print("Successfully created bucket {}".format(name))
except boto.exception.StorageCreateError as e:
print("Failed to create bucket: ", e)
我已经设置了 .boto 文件,当我运行它时,我收到类似错误
path = '/' + bucket
类型错误:无法将"字节"对象隐式转换为 str
您可以在使用之前尝试解码 uri:
uri.decode('utf-8')
或者你可以从一开始就把它读成 utf-8 像这样:
with open(file_path, encoding='utf-8') as file:
uri = file.read()
老实说,我认为这个问题与编码有关。如果我的建议不起作用,请告诉我,我会进一步研究这个方向。
编辑:
你也可以尝试像这样获取"uri"对象:
uri = boto.storage_uri("%s/%s" % (BUCKET_NAME, DOWNLOAD_PATH), 'gs')