skip to Main Content

enter image description here

`

@user.post("/add-user")
async def write_user_date(user: User):

    conn.execute(users.insert().values(
        name=user.name,
        email=user.email,
        password=user.password,
    ))
    return conn.execute(users.select()).fetchall()

`

That is my code, but every time when I post a data it’s show

ERROR: Exception in ASGI application Traceback (most recent call last): File "c:usershpdesktopfastapi projectvenvlibsite-packagesfastapiencoders.py", line 152, in jsonable_encoder data = dict(obj) TypeError: cannot convert dictionary update sequence element #0 to a sequence

this error. How to resolve it?

this error. How to resolve it?

2

Answers


  1. Chosen as BEST ANSWER

    Hello I solved this issue by changing my virtual environment This issue created from virtual environment, lib folder.


  2. Convert your data to dictonary first for example data = user.dict(), then you can get the values from dictionary and insert it in your database.

    On side note never store passwords as it is, always hash your passwords you can use from passlib.context import CryptContext. This makes easier to hash and verify the hash.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search