TypeError: 'psycopg2._psycopg.Binary' object does not support indexing

Question:

I need your help, I’m trying to insert files (.txt) to postgres using psycopg2 with python, but sends this error and don’t understand…

error:

TypeError: 'psycopg2._psycopg.Binary' object does not support indexing

I have:

archivo=open("coordenada.out",'rb').read()

cur.execute("insert into fhi(coordenadas) values(%s)",(psycopg2.Binary(archivo)))
Asked By: Schiffer

||

Answers:

You are missing a comma:

(psycopg2.Binary(archivo),)

It expects an iterable. The comma will make it a tuple. Otherwise it will try to iterate over the Binary

Answered By: Clodoaldo Neto
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.