M
Morten Goodwin Olsen
Python, PostgreSQL and bytea
Hi
I am having a bit of trouble inserting images into a postgres database
using python. The images should be stored in a bytea field.
I have tried both with an odbc connection and psycopg.
The python code is as following:
conn = PgSQL.connect(connectionString) # or psycopg og odb
curs = conn.cursor()
data = {}
blob = conn.binary(open('temp.jpg','rb').read())
sql = "Insert into imagetabel(image) values(%s )" print sql
curs.execute(sql,blob)
Using psycopg, the error is the follwing:
ProgrammingError: syntax error at or near "" at character 1
Using odcb, the error is:
TypeError: argument 1 must be string without null bytes, not str
While escaping the null bytes (string.replace(..., \0, "") - just to
see if the helped), the error changed to dbi.operation-error: ODBC
escape convert error in EXEC
Creating the same application using Java went without any errors.
I would be glad if someone new how to get around this problem.
Morten Goodwin Olsen
Hi
I am having a bit of trouble inserting images into a postgres database
using python. The images should be stored in a bytea field.
I have tried both with an odbc connection and psycopg.
The python code is as following:
conn = PgSQL.connect(connectionString) # or psycopg og odb
curs = conn.cursor()
data = {}
blob = conn.binary(open('temp.jpg','rb').read())
sql = "Insert into imagetabel(image) values(%s )" print sql
curs.execute(sql,blob)
Using psycopg, the error is the follwing:
ProgrammingError: syntax error at or near "" at character 1
Using odcb, the error is:
TypeError: argument 1 must be string without null bytes, not str
While escaping the null bytes (string.replace(..., \0, "") - just to
see if the helped), the error changed to dbi.operation-error: ODBC
escape convert error in EXEC
Creating the same application using Java went without any errors.
I would be glad if someone new how to get around this problem.
Morten Goodwin Olsen