bucket.cors
is a sequence mapping of each CORS policy.
Since you're not sharing exactly how you're updating your CORS entries, I assume that you're passing a dictionary of multiple key-value pairs to be appended. This fails silently since it's not matching the expected schema for policy entries.
Instead, write
import os
os.environ.update(
{'GOOGLE_APPLICATION_CREDENTIALS': '<path-to-your-key-file>'}
)
import google.cloud.storage
storage_client = google.cloud.storage.Client()
bucket_name = '<your-bucket-name>'
bucket = storage_client.get_bucket(bucket_name)
policies = bucket.cors
policies.extend([
{'origin': ['http://hello-world.example']},
{'maxAgeSeconds': 3600}
])
bucket.cors = policies
bucket.update()
print(bucket.cors)
Note that the origin is a list of origins to receive CORS response headers as documented in the Storage JSON API web document. Other policies must be passed with the correct value type as well.
You can also choose to append each policy individually this way:
...
policies.append(
{'origin': ['http://hello-world.example']},
)
policies.append(
{'maxAgeSeconds': 3600}
)