亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python連接數據庫出錯

python連接數據庫出錯

qq_莫非 2019-07-31 20:26:44
python連接數據庫出錯import?pymysql con=pymysql.connect(host='127.0.0.1',user='root',passwd='1997520', ????????????????????port=3306,db='test1') cur=con.cursor() list=[("52192325124","liujihong","124")] cur.execute('insert?into?student(Uid,Uname,Upassword)?values(%s,%s,%s)',list) con.commit() #?cur.execute('select?*?from?student') #?res=cur.fetchall() #?for?row?in?res: #?????print(row[0]) cur.close() con.close() 報錯如下: Traceback?(most?recent?call?last):??File?"D:/Python/workspace/Pysql/Mysql.py",?line?8,?in?<module>????cur.execute('insert?into?student(Uid,Uname,Upassword)?values(%s,%s,%s)',list)??File?"D:\Python\workspace\Pysql\venv\lib\site-packages\pymysql\cursors.py",?line?168,?in?execute????query?=?self.mogrify(query,?args)??File?"D:\Python\workspace\Pysql\venv\lib\site-packages\pymysql\cursors.py",?line?147,?in?mogrify????query?=?query?%?self._escape_args(args,?conn)TypeError:?not?enough?arguments?for?format?string
查看完整描述

4 回答

已采納
?
慕數據8021029

TA貢獻1條經驗 獲得超0個贊

list=[("52192325124","liujihong","124")]

cur.execute('insert?into?student(Uid,Uname,Upassword)?values(%s,%s,%s)',list)


改成


list=["52192325124","liujihong","124"]

cur.execute('insert?into?student(Uid,Uname,Upassword)?values(%s,%s,%s)',list)

查看完整回答
反對 回復 2019-08-01
?
安浪創想

TA貢獻81條經驗 獲得超23個贊

字符串格式錯誤,你字符串三個變量,而實際后面只傳了一個變量。你不能用一個含有三個元素的數組去代表這三個變量、

修正:

import?pymysql

con?=?pymysql.connect(host='127.0.0.1',?user='root',?passwd='root',
??????????????????????port=3306,?db='pytest')
cur?=?con.cursor()

list?=?["52192325124",?"liujihong",?"124"]
cur.execute('insert?into?student(Uid,Uname,Upassword)?values(%s,%s,%s)',?list)
con.commit()


查看完整回答
1 反對 回復 2019-08-01
  • 4 回答
  • 0 關注
  • 1426 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號