Ok, found it, I had to add an .decode('utf-8') ... :

user = self.params.get('user')
password = self.params.get('password')

if user and password:
    password = md5(password.decode('utf-8').hexdigest()
    condition = and_(User.c.login==user.decode('utf-8'), 
User.c.password==password)
    try:
        user_object = query_user.selectfirst(condition)
    except:
       self.addPageError('fatal', 'Sorry but an error occured. Please 
try again later')

Any idea why I have to add this with psycopg2 ? (my database is in 
Unicode UTF-8 and I connect with encoding='utf-8')

Thanks

Julien Cigar wrote:
> Hello,
>
> I just switched from psycopg1 to psycopg2 (with SQLAlchemy 0.2.6) and 
> the following code which worked fine with psycopg1 fail with psycopg2 :
>
> user = self.params.get('user')
> password = self.params.get('password')
>
> if user and password:
>     password = md5(password).hexdigest()
>     condition = and_(User.c.login==user, User.c.password==password)
>     try:
>         user_object = query_user.selectfirst(condition)
>     except:
>        self.addPageError('fatal', 'Sorry but an error occured. Please 
> try again later')
>
> (...)
>
> SQLError: (ProgrammingError) can't adapt 'SELECT users.first_name AS 
> users_first_name, users.name AS users_name, users.email AS users_email, 
> users.login AS users_login, users.password AS users_password, users.id AS 
> users_id \nFROM users \nWHERE users.login = %(users_login)s AND 
> users.password = %(users_password)s ORDER BY users.id \n LIMIT 1' 
> {'users_login': 'foobar', 'users_password': 
> '827ccb0eea8a706c4c34a16891f84e7b'}
>
> any idea ?
>
> Thanks,
> Julien
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
>   


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to