pymysql链接时,密码含有特殊符号。

类如含有@之类的特殊符号,在链接数据库时,需要提前url转码,不然会报密码错误。

python3/2分别引用是同样的第三方库,但是引用方式不同


python2


from urllib import quote_plus as urlquote


password = urlquote('password')

 

db_data = pymysql.connect(host='127.0.0.1',user='root'.password = password,db = 'test',port=3306,charser='utf8')


到了python3,quote_plus成了parse的函数

python3

 

from urllib import parse

 

password = parse.unquote_plus('password')

 

db_data = pymysql.connect(host='127.0.0.1',user='root'.password = password,db = 'test',port=3306,charser='utf8')

posted @ 2020-04-01 17:13  旧时候  阅读(2771)  评论(0)    收藏  举报