For some reason, I am unable to pass a parameter and I get the following error, however, if I were to remove the string, everything behaves properly. If anyone else has come across a such an error please let me know how to resolve it!
This is what my API looks like:
@router.post("/post")
async def post_request(
db: Session = Depends(database.get_db(string_here="string")
):
return ...
and a database file with
def get_db(string_here: str):
.... returns a db
ERROR:
raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: <generator object get_db at 0x000001FCFD7A8900> is not a callable object
This seems to have resolved my problem. I don't fully understand why it works, but it does. If someone wants to clarify the logic behind it, I would appreciate it.
https://stackoverflow.com/a/12074749/18347899
You don't need to call your generator, remove the () brackets.
You are probably confused by the fact that you use the same name for the variable inside the function as the name of the generator; the following will work too:
A parameter passed to the
somefunfunction is then bound to the local lengen variable instead oflengths, to make it clear that that local variable is not the same thing as thelengths()function you defined elsewhere.