Python3学习:Error整理

一、与 MySQL 数据库连接

  1. 关于编码
  • 修改之前
conn = pymysql.connect(
            host = MySql_Host_ip,
            port = MySql_Port,
            user = MySql_User,
            passwd = MySql_Password,
            db = MySql_Db)
  • 问题描述
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 43-44: ordinal not in range(256)

pymysql是没有指定编码类型

  • 修改之后
conn = pymysql.connect(
            host = MySql_Host_ip,
            port = MySql_Port,
            user = MySql_User,
            passwd = MySql_Password,
            db = MySql_Db,
            use_unicode = True,
            charset = "utf8")

你可能感兴趣的:(Python3学习:Error整理)