English 中文(简体)
FastAPI api giving "str type expected" error
原标题:

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.

问题回答

暂无回答




相关问题
Programmatic HTML POST with C#.NET 1.1

I m trying to integrate the Moneris Hosted Pay Page into my .net 1.1 app with an iFrame. I ve done this many times before, but not with .net 1.1. I can t seem to find a good resource for doing a ...

Receive POST from External Form

I have a form on another website (using a different backend) that I want to be able to POST to my Rails application (on a different domain). How do I generate a valid authenticity token for the ...

Getting posted values in MVC PartialView

I ve created a PartialView which I render with Html.RenderPartial, passing the name of the view and the strongly-typed data item to bind to (below): <% Html.RenderPartial("...

Create new etherpad using PHP and CURL

I m trying to write a simple PHP script which automatically sets up new etherpads (see http://etherpad.com/). They don t have an API (yet) for creating new pads so I m trying to figure if I can do ...

How to get unselected checkbox?

I have three checkboxes like ch[0], ch[1] and ch[3] (sometimes i have more, or less, it s dinamic) and in PHP i want to get the unselected items also, like this: 0=yes,1=no,3=yes and so on. Can I ...

热门标签