psycopg2“ TypeError:不是在字符串格式化期间转换的所有参数” [英] psycopg2 "TypeError: not all arguments converted during string formatting"
本文介绍了psycopg2“ TypeError:不是在字符串格式化期间转换的所有参数”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将二进制数据(漩涡哈希)插入PG表并收到错误:
I'm trying to insert binary data (a whirlpool hash) into a PG table and am getting an error:
TypeError: not all arguments converted during string formatting
code:
cur.execute("""
INSERT INTO
sessions
(identity_hash, posted_on)
VALUES
(%s, NOW())
""", identity_hash)
我尝试添加conn.Binary( identity_hash)插入变量之前,但是会得到相同的错误。
I tried adding conn.Binary("identity_hash") to the variable before insertion, but get the same error.
identity_hash列是一个bytea。
The identity_hash column is a bytea.
有什么想法吗?
推荐答案
您是否看过 examples / binary.py脚本在psycopg2的源代码发行中?它在这里工作正常。它看起来与您的摘录有些不同:
Have you taken a look at the "examples/binary.py" script in the psycopg2 source distribution? It works fine here. It looks a bit different than your excerpt:
data1 = {'id':1, 'name':'somehackers.jpg',
'img':psycopg2.Binary(open('somehackers.jpg').read())}
curs.execute("""INSERT INTO test_binary
VALUES (%(id)s, %(name)s, %(img)s)""", data1)
这篇关于psycopg2“ TypeError:不是在字符串格式化期间转换的所有参数”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文