I'm trying to move csv files between two existing buckets on GCP. But I'm stuck on an 'Not Found' Error. Here is the code I'm using (This was built after reading GCP docs and SDK's):
from google.cloud import storage
def move_blob(bucket_name, blob_name, destination_bucket_name, destination_blob_name):
"""Moves a blob from one bucket to another with a new name."""
storage_client = storage.Client()
source_bucket = storage_client.bucket(bucket_name)
source_blob = source_bucket.blob(blob_name)
destination_bucket = storage_client.bucket(destination_bucket_name)
blob_copy = source_bucket.copy_blob(
source_blob, destination_bucket, destination_blob_name
)
print(
"Blob {} in bucket {} moved to blob {} in bucket {}.".format(
source_blob.name,
source_bucket.name,
blob_copy.name,
destination_bucket.name,
)
)
def list_blobs():
"""Lists all the blobs in the bucket."""
bucket_name = "BUCKET_1"
destination_bucket_name = "BUCKET_2/folder"
storage_client = storage.Client()
blobs = storage_client.list_blobs(bucket_name)
for blob in blobs:
print(blob.name)
destination_blob_name = blob_name = blob.name
move_blob(bucket_name, blob_name, destination_bucket_name, destination_blob_name)
list_blobs()
And the content from the error message is:
'NotFound: 404 GET https://storage.googleapis.com/storage/v1/b/BUCKET_2/folder?projection=noAcl&prettyPrint=false: Not Found'