From ca861347827afe0cdc385014d218c71b96fa8c5b Mon Sep 17 00:00:00 2001 From: Andrew Snowden Date: Thu, 29 May 2014 18:23:29 +0200 Subject: [PATCH] Work around BucketAlreadyOwnedByYou Buckets outside of the standard region will raise an error if you try create them and they already exist. See: https://forums.aws.amazon.com/thread.jspa?threadID=119095 --- flask_s3.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flask_s3.py b/flask_s3.py index 20637bc..316bf2c 100644 --- a/flask_s3.py +++ b/flask_s3.py @@ -184,7 +184,14 @@ def create_all(app, user=None, password=None, bucket_name=None, conn = S3Connection(user, password) # connect to s3 # get_or_create bucket try: - bucket = conn.create_bucket(bucket_name, location=location) + try: + bucket = conn.create_bucket(bucket_name, location=location) + except S3CreateError as e: + if e.error_code == u'BucketAlreadyOwnedByYou': + bucket = conn.get_bucket(bucket_name) + else: + raise e + bucket.make_public(recursive=True) except S3CreateError as e: raise e