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.
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'
}
]
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With