2017/05/10

之前在centos上執行python的cgi都沒問題
但移植到ubuntu 16.04上後一直出現如下的error

File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 210, in execute
    query = query % args
TypeError: not all arguments converted during string formatting

程式完全一樣都沒改啊

google了半天 才解決問題
差異如下

ubuntu 16.04

sql = "delete from abc where ip=%s"
cursor.execute(sql, [ip])

變數一定要用 [ ] 包住

centos 7

sql = "delete from abc where ip=%s"
cursor.execute(sql, ip)


http://stackoverflow.com/questions/21740359/python-mysqldb-typeerror-not-all-arguments-converted-during-string-formatting

沒有留言: