오지's blog

mysql관련 python 프로그램 에러 TypeError: not all arguments converted during string formatting 본문

개발노트/데이터베이스

mysql관련 python 프로그램 에러 TypeError: not all arguments converted during string formatting

오지구영ojjy90 2021. 3. 15. 22:23
728x90
반응형

분명 sqlite에서는 발생하지 않은 에러가 mysql로 변경하니 발생한다.

에러 메세지는 TypeError: not all arguments converted during string formatting

sql = """INSERT INTO test_tb(id, name) VALUES(?,?)""" # ERROR

sql = """INSERT INTO test_tb(id, name) VALUES(%s,%s)""" # 에러 발생하지 않음

 

 

def insert_one_row(conn, insert_vals):
print(type((insert_vals)))
sql = """INSERT INTO test_tb(id, name) VALUES(?,?)""" # ERROR
# sql = """INSERT INTO test_tb(id, name) VALUES(%s,%s)"""
cur = conn.cursor()
cur.execute(sql, insert_vals)
conn.commit()
sql_print(sql)
return cur.lastrowid

 

?에서 %로 변경하면 에러 발생하지 않음

 

Comments