Server's built-in httpx module POST Issues

I was trying to customize the KitsuAddon to suit my studio’s needs.
Problem is, whenever I try to send any POST request, All kinds of errors appear (uvloop is one of the errors).
I tried to send data in body, query, even in the url path, but nothing seems to work.
When I debug and test the request syntax with a third party IDE, everything works just fine.
seems like there is a problem with the ayon_server built-in httpx module.
What am I supposed to do so I can send the data properly?

Images for reference:

The images weren’t showing up properly. I hope you don’t mind my edits to show them.

1 Like

As @martin.wacker pointed out on Discord:

I believe endpoints must return either fastapi.Response or a subclass of pydantic.BaseModel (or ayon_server.types.OPModel the response from httpx is a plain dict and fastapi tries to call the dict() method of the response

Potentially this FastAPI Response Model reference might be helpful additionally.

Sorry, i was wrong yesterday as i was responding from the phone:

addon.kitsu.post does not return dict, but a httpx.Response object (with response headers, status code and so on). so you should do:

response = await addon.kitsu.post(url, data=data)
return response.json()

(with some error handling such as response.raise_for_status())

Plain dicts actually work as a return type (i usually use pydantic models to have response schema validated):


    def initialize(self):
        self.add_endpoint(
            "test",
            self.test_endpoint,
            method="GET",
        )

    async def test_endpoint(self):
        return {"test": "OK"}
$ http get http://localhost:5000/api/addons/example/2.0.1+git/test
HTTP/1.1 200 OK
content-length: 13
content-type: application/json
date: Wed, 21 Feb 2024 07:16:38 GMT
server: uvicorn

{
    "test": "OK"
}
1 Like

Get requests are fine, The problem is precisely in POST requests

If I haven’t read the Fastapi docs already I wouldn’t have tried editing the code.
problem isn’t with getting the response, my problem is in sending data in the post request, which raises an error

oh. sorry. i misunderstood that part. could you try with

response = await addon.kitsu.post(url, json=your_payload_dict)
return response.json()

with data httpx sends the payload urlencoded, while with json its dumps the payload to a json string and sends appropriate Content-Type: application/json header

Still, not working either