1

我试图在这个问题中应用建议,但我似乎仍然没有让代码工作。我正在尝试传递两个变量

如何将python烧瓶中的变量传递给mysqldb?

cur = mysql.connection.cursor()
for row in jdict:
  headline = row['title']
  url = row['url']
  cur.execute("INSERT INTO headlinetitles (Title, Url) VALUES ('%s','%s');",str(headline),str(url))
mysql.connection.commit()

我收到错误 TypeError: execute() 需要 2 到 3 个位置参数,但给出了 4 个

4

1 回答 1

1

我找到了解决方案。也许这会对某人有所帮助。

cur = mysql.connection.cursor()
for row in jdict:
    headline = row['title']
    url = row['url']
    sqldata = ("INSERT INTO headlinetitles (Title, Url) VALUES ('%s','%s');",str(headline),str(url))
    cur.execute = (sqldata)
mysql.connection.commit()
于 2020-12-20T17:18:11.137 回答