0

My code is throwing:

botocore.errorfactory.BatchEntryIdsNotDistinct: An error occurred (AWS.SimpleQueueService.BatchEntryIdsNotDistinct) when calling the DeleteMessageBatch operation: Id 85990c40-xxxx-43f5-a66e-80618a734157 repeated.

I would like to catch the exception, but can't import it:

from botocore.errorfactory import BatchEntryIdsNotDistinct
ImportError: cannot import name 'BatchEntryIdsNotDistinct' from 'botocore.errorfactory' 

It doesn't even seem to exist as python code, just as json:

grep -r BatchEntryIdsNotDistinct .
./lib/python3.9/site-packages/botocore/data/sns/2010-03-31/service-2.json:        {"shape":"BatchEntryIdsNotDistinctException"},
./lib/python3.9/site-packages/botocore/data/sns/2010-03-31/service-2.json:    "BatchEntryIdsNotDistinctException":{
./lib/python3.9/site-packages/botocore/data/sns/2010-03-31/service-2.json:        "code":"BatchEntryIdsNotDistinct",
./lib/python3.9/site-packages/botocore/data/sqs/2012-11-05/service-2.json:        {"shape":"BatchEntryIdsNotDistinct"},
./lib/python3.9/site-packages/botocore/data/sqs/2012-11-05/service-2.json:        {"shape":"BatchEntryIdsNotDistinct"},
./lib/python3.9/site-packages/botocore/data/sqs/2012-11-05/service-2.json:        {"shape":"BatchEntryIdsNotDistinct"},
./lib/python3.9/site-packages/botocore/data/sqs/2012-11-05/service-2.json:    "BatchEntryIdsNotDistinct":{
./lib/python3.9/site-packages/botocore/data/sqs/2012-11-05/service-2.json:        "code":"AWS.SimpleQueueService.BatchEntryIdsNotDistinct",

This is my code (shortened):

sqs = boto3.resource('sqs', region_name='us-west-2')
queue = sqs.get_queue_by_name(QueueName=<queue name here>)
queue.delete_messages(Entries=<messages to delete>)

Where do I get the exception BatchEntryIdsNotDistinct from to catch it?

kev
  • 8,928
  • 14
  • 61
  • 103
  • try `sqs.exceptions.BatchEntryIdsNotDistinct` not need to import just use with exception block `sqs` is the resource name you used in the code. ref this https://stackoverflow.com/questions/33068055/how-to-handle-errors-with-boto3 – Deepan Aug 09 '22 at 02:20
  • trying `sqs.exceptions.BatchEntryIdsNotDistinct` gives me `'sqs.ServiceResource' object has no attribute 'exceptions'` – kev Aug 09 '22 at 03:14
  • 1
    They used client instead of resource may can you try that? – Deepan Aug 09 '22 at 03:16

1 Answers1

1

I found it here:

sqs.meta.client.exceptions.BatchEntryIdsNotDistinct as e

using like this worked:

except sqs.meta.client.exceptions.BatchEntryIdsNotDistinct as e
kev
  • 8,928
  • 14
  • 61
  • 103