问题:'NoneType' object has no attribute 'encoding'

conn = pymysql.connect(host="localhost", user="root", passwd="123456", db="dd")

python链接mysql数据库问题:python

个人代码运行卡在这条代码就执行不下去了!mysql

这条代码自己并无问题,可是所引用的connection.py包中要设置一下charset的值“utf8”(或者“utf-8”,可能版本不同会有所不一样)sql

在C:\Users\xh\AppData\Local\Programs\Python\Python37\Lib(根据本身下载的自我调节)找到下面这个模块进行相应的设置:数据库

def __init__(self, host=None, user=None, password="",
                 database=None, port=0, unix_socket=None,
                 charset="utf8", sql_mode=None,
                 read_default_file=None, conv=None, use_unicode=None,
                 client_flag=0, cursorclass=Cursor, init_command=None,
                 connect_timeout=10, ssl=None, read_default_group=None,
                 compress=None, named_pipe=None,
                 autocommit=False, db=None, passwd=None, local_infile=False,
                 max_allowed_packet=16*1024*1024, defer_connect=False,
                 auth_plugin_map=None, read_timeout=None, write_timeout=None,
                 bind_address=None, binary_prefix=False, program_name=None,
                 server_public_key=None):
        if use_unicode is None and sys.version_info[0] > 2:
            use_unicode = Truesocket

相关文章
相关标签/搜索