Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Boto3 Delete Objects Failing with TypeError: delete_objects() only accepts keyword arguments

I have Boto3 working fine in my Flask project for saving and retrieving files but I'm having trouble with deleting. I have the below code:

s3 = g_setupboto3('client')

saved_images = s3.list_objects_v2(
        Bucket=app.config['BUCKET'],
        Prefix='studio/mbr/' + str(member_id) + '/'
        + str(slide_id) + '/img',
        MaxKeys=100)

aaa = s3.delete_objects(
    app.config['BUCKET'],
    Delete={
        'Objects': [
            {
                'Key': '/studio/mbr/1/5f184eba68bed55f2782b2a6/img/0ce9a2c0cde639f228b213e72d559662f29ebe1f.png'
            },
            {
                'Key': '/studio/mbr/1/5f184eba68bed55f2782b2a6/img/5cd3fa567d0cf623f21ce07d73d3e6c556ce8a98.png'
            }
        ]
    }
)

print('aaa: ' + str(aaa))

the retrieval of saved_images works fine but the delete_objects call generates the following error:

File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 274, in _api_call
web_1       |     "%s() only accepts keyword arguments." % py_operation_name)
web_1       | TypeError: delete_objects() only accepts keyword arguments.

Am I missing something obvious here? I can't find anything online covering this.

Thanks.

like image 668
N.Widds Avatar asked Oct 26 '25 06:10

N.Widds


1 Answers

Based on the delete_objects docs, you should use Bucket keyword to specify the bucket:


aaa = s3.delete_objects(
    Bucket=app.config['BUCKET'],
    Delete={
        'Objects': [
            {
                'Key': '/studio/mbr/1/5f184eba68bed55f2782b2a6/img/0ce9a2c0cde639f228b213e72d559662f29ebe1f.png'
            },
            {
                'Key': '/studio/mbr/1/5f184eba68bed55f2782b2a6/img/5cd3fa567d0cf623f21ce07d73d3e6c556ce8a98.png'
            }
        ]
    }
)
like image 149
Marcin Avatar answered Oct 28 '25 21:10

Marcin