Python 连接musql报错“TypeError: d format: a number is required, not str”

 

连接musql报错“TypeError: %d format: a number is required, not str”

Python 连接musql报错“TypeError: d format: a number is required, not str”_第1张图片

 

解决方法:

提示的“ self.host_info = "socket %s:%d" % (self.host, self.port)  TypeError: %d format: a number is required, not str”

说明port是一个number类型,而不是str类型。转换一下类型即可。

port_param_int=int(port_param) # 将port的类型转成number类型
        
db = pymysql.connect(host=host_param,user=user_param,password=pwd_param,db=db_param,port=port_param_int,

 

你可能感兴趣的:(Python)