1

I have to save a couple of different urls in some variable and then I have to return them from AWS Lambda function using json.dumps. I am trying the below method but it's giving me the error "errorMessage": "unhashable type: 'dict'". Code is given below.

response1 = { "statusCode": 200, "message": "Audio File uploaded successfully", "Link": some_variable1}
response2 = { "statusCode": 200, "message": "Spectrograph uploaded successfully", "Link": some_variable2}
response3 = {response1, response2}
   return {
   'statusCode': 200,
   'body': json.dumps(response3)
   }

Any idea how to get it working?

0

1 Answer 1

3

{response1, response2} is a set literal, which requires items to be hashable. In this case response1, response2 are dictionary which is not hashable.

>>> a_dictionary = {"statusCode": 200}
>>> {a_dictionary}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'

Instead of using set, you can use list or tuple which do not require items to be hashable.

>>> [a_dictionary]
[{'statusCode': 200}]
>>> (a_dictionary,)
({'statusCode': 200},)
response3 = [response1, response2]  # list
# or
response3 = (response1, response2)  # tuple
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.