問題:'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

相關文章
相關標籤/搜索