Schiffer
Schiffer

Reputation: 21

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

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)))

Upvotes: 0

Views: 2410

Answers (1)

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125434

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

Upvotes: 3

Related Questions