Skip to content
Advertisement

sqlalchemy.exc.DataError: (psycopg2.DataError) value too long for type character varying

I Try to save a hashed Password in postgresql database using SQL Alchemy. table script is:

JavaScript

and this is the mapping:

JavaScript

when i try to insert data, this exception raised :

JavaScript

but as you see data is exactly fit too field and there is no error when i execute this query inside pgadmin! I think problem is in my mapping. i Changed String to Text but error resists :|

Any idea?

I don’t know if it help. when all characters are digits, code work’s with no error.

I try to insert some digits instead of hashed password and it works!

Update

I found that problem is character encoding! Some how SQLAlchemy increase size of passed string! Now i’am trying to prevent it!

Advertisement

Answer

Problem is not about mapping or charset or any things like that in sql Alchemy! it is my code! when i try to convert hashing result to base64 string, result will be a BinaryString! not a String.

‘password’: b’i1SlFeDkCZ0BJYanhING….

So to solve this problem i need to decode base64 result to unicode string befor save it to database!

u.password = u.password.decode(“utf-8”, “ignore”)

Advertisement