在Google文档中提供示例代码:
from google.cloud import storage
def download_blob(bucket_name, source_blob_name, destination_file_name):
"""Downloads a blob from the bucket."""
# The ID of your GCS bucket
# bucket_name = "your-bucket-name"
# The ID of your GCS object
# source_blob_name = "storage-object-name"
# The path to which the file should be downloaded
# destination_file_name = "local/path/to/file"
storage_client = storage.Client(project="cse6242team12project")
bucket = storage_client.bucket(bucket_name)
# Construct a client side representation of a blob.
# Note `Bucket.blob` differs from `Bucket.get_blob` as it doesn't retrieve
# any content from Google Cloud Storage. As we don't need additional data,
# using `Bucket.blob` is preferred here.
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
print(
"Downloaded storage object {} from bucket {} to local file {}.".format(
source_blob_name, bucket_name, destination_file_name
)
)
我已经检查了我的文件夹权限,当我在右键单击 - >属性下检查安全权限时,我的
destination_file_name
文件夹设置为“写”。
问题是什么?当我打电话给函数test
时,我仍然得到
PermissionError:[ERRNO 13]拒绝了:'c:/users'
download_blob("team12data", "housepricesLA.geojson", "C:/Users")
应该是您希望下载文件存在的文件(而不是目录)的路径。 看起来您正在传递目录,而不是文件。
destination_file_name