我试图将二进制数据(惠而浦散列)插入到PG表中,得到一个错误:
TypeError: not all arguments converted during string formatting
代码:
cur.execute("""
INSERT INTO
sessions
(identity_hash, posted_on)
VALUES
(%s, NOW())
""", identity_hash)
我尝试在插入之前将conn.Binary(“identity_hash”)添加到变量中,但得到了相同的错误。
identity_hash列是一个bytea。
有什么想法吗?
遇到同样的问题,发现这实际上包含在他们的FAQ
问题是,您将对象作为第二个参数传递:第二个参数应该是元组或dict。没有%string运算符中的快捷方式。
你应该:
你看过psycopg2源发行版中的“examples/binary.py”脚本吗?在这里工作很好。它看起来有点不同于你的摘录:
相关问题 更多 >
编程相关推荐