hello everyone! kedro-fast-api works? I am testi...
# questions
e
hello everyone! kedro-fast-api works? I am testing it, for this I have created a new project based on the starter pandas-iris. I run the "kedro run" and "kedro run --pipeline=api_pipeline" and everything is apparently fine.
now i start the api:
image.png
when i fill the inputs in the api i get this error:
This is the definition of the catalog and the catalog of the "api_pipeline"
this is the node and pipeline from "api_pipeline"
I check in "kedro jupyter lab" that it works, I'm replicating what the api is doing:
This is the error message that doesn't look good in the image:
Copy code
INFO:     Started server process [128335]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on <http://0.0.0.0:8000> (Press CTRL+C to quit)
INFO:     127.0.0.1:40112 - "GET / HTTP/1.1" 307 Temporary Redirect
INFO:     127.0.0.1:40112 - "GET /docs HTTP/1.1" 200 OK
INFO:     127.0.0.1:40112 - "GET /openapi.json HTTP/1.1" 200 OK
INFO:     127.0.0.1:48892 - "GET / HTTP/1.1" 307 Temporary Redirect
INFO:     127.0.0.1:48892 - "GET /docs HTTP/1.1" 200 OK
INFO:     127.0.0.1:48892 - "GET /openapi.json HTTP/1.1" 200 OK
INFO:     127.0.0.1:48896 - "GET /my_model?sepal_length=4&sepal_width=3&petal_length=2&petal_width=1 HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/fastapi/encoders.py", line 152, in jsonable_encoder
    data = dict(obj)
ValueError: dictionary update sequence element #0 has length 6; 2 is required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/fastapi/encoders.py", line 157, in jsonable_encoder
    data = vars(obj)
TypeError: vars() argument must have __dict__ attribute

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await <http://self.app|self.app>(scope, receive, send)
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/fastapi/applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await <http://self.app|self.app>(scope, receive, _send)
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await <http://self.app|self.app>(scope, receive, sender)
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await <http://self.app|self.app>(scope, receive, send)
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await <http://self.app|self.app>(scope, receive, send)
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/fastapi/routing.py", line 255, in app
    content = await serialize_response(
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/fastapi/routing.py", line 152, in serialize_response
    return jsonable_encoder(response_content)
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/fastapi/encoders.py", line 117, in jsonable_encoder
    encoded_value = jsonable_encoder(
  File "/home/coder/miniconda3/envs/demml/lib/python3.10/site-packages/fastapi/encoders.py", line 160, in jsonable_encoder
    raise ValueError(errors) from e
ValueError: [ValueError('dictionary update sequence element #0 has length 6; 2 is required'), TypeError('vars() argument must have __dict__ attribute')]
I managed to solve it, I had to return a list in the class "MLPredictor" in the nodes.py from "api_pipeline"
🙌 1
image.png
😉
d
Glad you were able to resolve it! This is the first I've personally heard of
kedro-fast-api
(as it's a third-party plugin), but looks cool, and maybe you can make a PR with the fix over there. 🙂
👍 1