1

I have tried to apply the advice in this question but I still don't seem to get the code to work. I am trying to pass two variables

How to pass variables in python flask to 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()

I get the error TypeError: execute() takes from 2 to 3 positional arguments but 4 were given

1 Answer 1

1

I found the solution. Maybe this will help someone.

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()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.