问题描述
我想使用psycopg2和python将图像插入Postgresql数据库。 但随后却显示此错误:
Traceback (most recent call last):
File "C:\Users\Superkalifragalistic\Documents\Python Scripts\lol.py",line 11,in <module>
cur.execute("""INSERT INTO cat_imgs (img) VALUES ({});""".format(dbimg))
psycopg2.errors.SyntaxError: Syntax error at or near "\"
LINE 1: ...x92\x10\xf6>\xfb\x9cd}\x9e\xc7\xe7\x91=\xac\xf5=\'\xfb{\xd6\...
这是我的代码:
import psycopg2 as pcpg
img = r'C:\Users\Superkalifragalistic\Documents\Python Scripts\cat.png'
with open(img,'rb') as p:
image = p.read()
dbimg = str(image)
conn = pcpg.connect(database = 'cats',user = 'postgres',password = '*******')
cur = conn.cursor()
cur.execute("""INSERT INTO cat_imgs (img) VALUES ({});""".format(dbimg))
conn.commit()
conn.close()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)