SQL syntax error - Python

Asked

Viewed 42 times

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': inserir a descrição da imagem aqui

  • Are you sure you should have this , in res, ))?

  • I took out the comma, but it still shows a syntax error...

  • Copy and paste the error here

  • 1

    Has an extra comma at the end of query values as well: (%s, %s, %s, %s, %s,)'''

  • That’s right Lucas, thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.