How to resolve "An Attributevalue may not contain an Empty string"?

Asked

Viewed 121 times

1

Hello,

I am doing some simple tests for integration of the API Gateway with Dynamodb, at this moment I can do a GET and POST using POSTMAN and GET in python, but I cannot do the POST in Python, I have a bug

One or more Parameter values Were invalid: An Attributevalue may not contain an Empty string

(returns from AWS) but I can’t verify what is going empty being that the body of the request is the same as I use in POSTMAN.

Has anyone gone through this or has any idea if it might be some wrong parameter in python ?

follows screen:

inserir a descrição da imagem aqui

import requests
import json

###################################################
####ETAPA - CHAMADO API PARA POST##################
###################################################
print('10º ETAPA - CHAMADO API POST')

payload = [
            {
            "id": 10,
            "cont_id": "Monday",
            "idade": 15,
            "name": "Test with python",
            }
          ]
print(str(payload))
try:
  #chamar API POST
  url = 'https://bswv8.execute-api.us-east-2.amazonaws.com/dev/gravar'
  print('URL API Post: ', url)
  headers = {
      "Content-Type": "application/json",
      'Accept': 'application/json'
  }
  response = requests.post(url, json=payload, headers=headers)
  print(response.text)

except Exception as e:
  print('ETAPA: ERRO ac chamar API para o POST')

finally:
  print('ETAPA: Chamada a API POST bem sucedido')

Thanks for your help

Abs

  • Please edit the question and put your code as code, not as image (paste here and use the button {} to format. Do the same with the full error message.

  • HI @jsbueno. Done and thanks for the guidance..

  • Two things: 1) your JSON is not properly formatted (it has a comma after the last parameter - after "Test with python"); 2) you have already run the test trying to pass data=payload instead of json=payload?

  • Hi @Murilositonio, thanks for the reply. I tried to change the 'json=payload' to 'data=payload' but the error remains the same, saying that I am passing an empty string, even after having taken the comma according to its orientation. Actually when I change to 'data=payload' it can’t even reach the API, IE, nor have the return of the empty string

1 answer

0


For those who stop at this difficulty, I was able to make my code work by removing the brackets and keeping only the keys, at the time I am preparing the json file:

got:

payload = {
        "id": 10,
        "cont_id": "Monday",
        "idade": 15,
        "name": "Test with python",
          }
  • And understood why it solved the problem?

  • No, but I believe that using the brackets dynamoDB identifies some empty string (this was the error). Which makes sense because the same layout used in Postman and the AWS tool itself works, the only difference was the brackets to mount the json file in python. But if anyone has a better explanation, I’d really appreciate it.

  • 1

    With square brackets you define a list of objects, but dynamoDB expects only one object.

  • Good @Andersoncarloswoss thanks for summing up and making it clear ! Thanks really.

  • @Andersoncarloswoss the post already has a while but I came across a problem and remembered your answer. I need to send a single json with several objects but Dynamodb does not accept, would you have any material to forward ? I can’t find anything relevant.Hugs.,

Browser other questions tagged

You are not signed in. Login or sign up in order to post.