0
I have the following code
import json
import io
import psycopg2
connection = psycopg2.connect("dados da conexão")
connection.autocommit = True
cursor = connection.cursor()
readTest = io.open("arquivo.json", encoding = "utf-8")
readAll = readTest.readlines()
cursor. executemany("INSERT INTO tabela (coluna) VALUES (%s)",(readAll))
When I insert the.json file with a single line the same works but when using more than 2 lines the same appears the following error:
TypeError: not all arguments converted during string formatting
Example of.json file content with more than two lines
{"id":"BRA","count":2,"distance":0.8,"longitude":-80.004114}
{"id":"USA","count":9,"distance":1.2,"longitude":-20.011111}
For more than one line you do not use the
execute
, but rather theexecutemany
.– Woss
I made the change to executemany and still contains the same error of the question( I will change in the question)
– SrLima