Python Forum
pymysql: insert query throws error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pymysql: insert query throws error
#5
Thanks for the explanation. I now see the result of:
qry = "INSERT INTO rules (%s) VALUES (%s)" % (qmarks, qmarks)
... is:
Output:
INSERT INTO rules (?,?,?,?) VALUES (?,?,?,?)
This is wrong. The first qmarks should be column_names so that the result would be:
Output:
INSERT INTO rules (sudohost,users,hosts,commands) VALUES (?,?,?,?)
Then I see "qvals_stringed" contains:
Output:
INSERT INTO rules (?,?,?,?) VALUES (?,?,?,?) sudohost,users,hosts,commands,[['aixacodbt']],[[['root']]],[[['ALL']]],[[(['root'], ['ALL'], [{'run_as': ['ALL'], 'tags': None, 'command': 'ALL'}])]]
That is also wrong. It should contain a tuple with four elements like this:
Output:
('aixacodbt', 'root', 'ALL', "['root'], ['ALL'], [{'run_as': ['ALL'], 'tags': None, 'command': 'ALL'" )
If you got that fixed you should be able to execute:
cursor.execute(qry, qvals_stringed)
... without error.
Reply


Messages In This Thread
pymysql: insert query throws error - by wardancer84 - Jan-21-2022, 12:54 PM
RE: pymysql: insert query throws error - by ibreeden - Jan-24-2022, 11:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  sqlite3 Conn Insert Value Error TylerDunbar 3 782 Sep-04-2023, 06:32 PM
Last Post: deanhystad
  pymysql; insert on duplicate key update fails wardancer84 4 2,069 Jun-28-2022, 08:14 PM
Last Post: Larz60+
  Mysql Syntax error in pymysql ilknurg 4 2,414 May-18-2022, 06:50 AM
Last Post: ibreeden
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,284 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  Query Syntax Error hammer 2 1,649 Jan-03-2022, 02:30 PM
Last Post: hammer
  pymysql can't do SELECT * Pedroski55 3 3,014 Sep-11-2021, 10:18 PM
Last Post: Pedroski55
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,182 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  Error using mariadb select query with form in python? shams 2 2,053 Jul-29-2021, 12:30 PM
Last Post: shams
  pyarrow throws oserror winerror 193 1 is not a valid win32 application aupres 2 3,833 Oct-21-2020, 01:04 AM
Last Post: aupres
  Function throws error but then works? Milfredo 10 3,846 Sep-12-2020, 05:16 AM
Last Post: Milfredo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020