0
I have a flask application in which one of the features (log_request) is to record data from a form in an SQL database. When running def log_request, however, I have an error accusing incorrect syntax. I have reviewed several times and could not identify such errors in def:
def log_request(req: 'flask_request', res: str) -> None:
dbconfig = {'user': 'vsearch',
'password': 'vsearchpasswd',
'host': '127.0.0.1',
'database': 'vsearchlogDB',}
import mysql.connector
conn = mysql.connector.connect(**dbconfig)
cursor = conn.cursor()
_SQL = '''insert into log
(phrase, letters, ip, browser_string, results)
values
(%s, %s, %s, %s, %s,)'''
cursor.execute(_SQL, (req.form['phrase'],
req.form['letters'],
req.remote_addr,
req.user_agent.browser,
res, ))
conn.commit()
cursor.close()
conn.close()
As you can see the structure of my db is as I called (table 'log' inside db 'vsearchlogDB':
Are you sure you should have this
,
inres, ))
?– anonimo
I took out the comma, but it still shows a syntax error...
– Leonardo Gouvêa Silva
Copy and paste the error here
– Sinf0r0s0
Has an extra comma at the end of query values as well:
(%s, %s, %s, %s, %s,)'''
– Lucas Marcondes Pavelski
That’s right Lucas, thank you!
– Leonardo Gouvêa Silva