#๐Ÿ”’ Pydantic Error

11 messages ยท Page 1 of 1 (latest)

weary idol
#
import fastapi
from typing import List, Optional, Dict, Annotated
from pydantic import BaseModel

app = fastapi.FastAPI()

class data_scheme:
    url: str
    


class RequestModel(BaseModel):
    iterate_through: List[data_scheme]

    


@app.get("/send-requests")
def get_request(request_model : RequestModel):
    return {"message": "Hello, World!"}


Whats wrong with this code?

It keeps giving this error.


pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class '__main__.data_scheme'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.

For further information visit https://errors.pydantic.dev/2.6/u/schema-for-unknown-type
cosmic latchBOT
#

@weary idol

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

weary idol
#

thanks in advance

ripe thorn
#

Your code makes no sense. What is the purpose of RequestModel? Right now the way you're using it implies it will be a json payload, but using get() doesn't allow that.

#

Maybe you meant to make data_scheme also inherit BaseModel?

#
class DataScheme(BaseModel):
  url: str

class RequestModel(BaseModel):
  iterate_through: List[DataScheme]
#

If you want it to be query params, define your endpoint like this. ```py
from fastapi import Query

@app.get("/send-requests")
def get_request(request_model: List[str] = Query()):
...

weary idol
#

!close

cosmic latchBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.