Reputation: 744
I'm trying to insert data into a db that is obtained from an API. I have used this previously without issue, and can't see what has changed for it to stop working. All fields are text fields except 'id', 'multiplier' and 'price', the first of which is handled by postgres.
I've ensured the number of format placeholders map the number of fields and that the query should be correct, so I can't see what the issue is.
Other answers to similar problems mentioned mixing string formatting, which is not the case here.
My code:
cur.execute("""INSERT INTO "public"."main_page_product" ("id","collection_name","description",
"multiplier","dimension","feat1","feat10","feat2","feat3",
"feat4","feat5","feat6","feat7","feat8","feat9","image_url",
"price","short_name","sku","meta_name")VALUES (nextval('catalogue_product_id_seq'::regclass),%s,%s,
'2.2',%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
(temp1['name'], temp1['short_description'], temp1['dimension'],
temp1['feat1'], temp1['feat2'], temp1['feat3'], temp1['feat4'],
temp1['feat5'], temp1['feat6'], temp1['feat7'], temp1['feat8'],
temp1['feat9'], temp1['feat10'], finurl, temp1['price'],
temp1['short_name'], temp1['sku'], temp1['meta_title']))
TypeError: not all arguments converted during string formatting
Upvotes: 0
Views: 64
Reputation: 51653
You have a mismatch between column-names and params:
INSERT INTO "public"."main_page_product"
("id","collection_name","description","multiplier", # 4
"dimension","feat1","feat10","feat2", # 4
"feat3","feat4","feat5","feat6", # 4
"feat7","feat8","feat9","image_url", # 4
"price","short_name","sku","meta_name") # 4
VALUES
(nextval('catalogue_product_id_seq'::regclass),%s,%s,'2.2', # 4
%s,%s,%s,%s, # 4
%s,%s,%s,%s, # 4
%s,%s,%s,%s, # 4
%s,%s,%s)""", # 3
Upvotes: 3