Problem Solved. The problem was with psycopg.Binary whose mere job is to convert bytes into clear text for sql statement. I'll be filing a bug. Thanks everyone, Sia