1

UPDATE: I downloaded the Uvicorn service and ran it again, then it worked

I have this code that returns the url of an amazon rds instance:

def get_host(instance_name):
    """This function receives the name of an RDS instance and returns its connection endpoint"""
    client = boto3.client('rds',
                        aws_access_key_id=AWS_ACCESS_KEY_ID,
                        aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
                        region_name=AWS_DEFAULT_REGION)
    instance = client.describe_db_instances(DBInstanceIdentifier=instance_name)['DBInstances'][0]
    endpoint = instance['Endpoint']['Address']
    print(endpoint)
    return endpoint  

and this api that calls it

@app.post("/host", tags=['host'])
def get_host_with_api(instance_name: str = Body()):
    return {"endpoint": get_host(instance_name)}.`

When I call the code directly using the function, like this: get_host("instance10") returns what I need, but when I use the api with postman I get this error:

{
    "detail": [
        {
            "loc": [
                "body"
            ],
            "msg": "str type expected",
            "type": "type_error.str"
        }
    ]
}

when the api call is of type post, i am sending the parameter to it as

{
    "instance_name":"instance10"
}

in the body as raw data in json, why does it send me this error? I tried with another api that also receives strings and I sent them with the same format and it does receive them, what is wrong?

I tried with another api that also receives strings and I sent them with the same format and it does receive them, what is wrong? I've tried calling only the function and the response is OK.

0 Answers0