pyinstaller exe“mysql.connector.errors.NotSupportedError:不支持身份验证插件‘mysql_native_password’”

问题描述 投票:0回答:1

我正在使用 python 连接到 sql 数据库。我的代码在控制台中运行良好,但是当我使用 pyinstaller 将其转换为 exe 时,出现此错误。
error

pyinstaller代码:python -m PyInstaller --noconsole --onefile --icon=icon.ico --name=Gkod main.py

from mysql.connector.plugins import caching_sha2_password
from mysql.connector.locales.eng import client_error
from tkinter import *
from tkinter import ttk
import mysql.connector, datetime

root = Tk()
root.geometry("340x100")
root.title("Gkod | by Niuren_")
root.resizable(False, False)

menu_bar = Menu(root)

now = datetime.datetime.now()
time = now.strftime("%H:%M:%S")

timeLabel = Label(root)
timeLabel.pack()

def reload():
    for widget in root.winfo_children():
        if widget is not timeLabel and widget is not menu_bar:
            widget.destroy()

    now = datetime.datetime.now()
    time = now.strftime("%H:%M:%S")
    timeLabel.config(text=time)

    config = {
            'user': '-',
            'password': "-",
            'host': '-',
            'database': '-',
            'charset': 'utf8',
            'auth_plugin': 'mysql_native_password'
        }
    with mysql.connector.connect(**config) as vt:
        im = vt.cursor()
        im.execute("""SELECT username, code FROM verification""")

        rows = im.fetchall()

        contacts = []

        for row in rows:
            sütun1 = row[0]
            sütun2 = row[1]
            contacts.append((sütun1, sütun2))
            
        if len(contacts) != 0:

            root.geometry("500x300")

            tree = ttk.Treeview(root, columns=("Kullanıcı Adı", "Kod"), show="headings")
            tree.place(relx=.5, rely=.5, anchor=CENTER)


            tree.heading("#0", text="sfd")
            tree.heading("Kullanıcı Adı", text="Kullanıcı Adı")
            tree.heading("Kod", text="Kod")

            for contact in contacts:            
                tree.insert('', END, values=contact)

            def item_selected(event):
                for selected_item in tree.selection():
                    item = tree.item(selected_item)
                    record = item['values']
                    root.clipboard_clear()
                    root.clipboard_append(record[1])
                    root.update()

            tree.bind('<<TreeviewSelect>>', item_selected)
        
        else:
            root.geometry("340x100")
            Label(text="Veri tabanında kayıt bulunamadı.", bg="lightgray", font=("family", 10)).place(relx=.5, rely=.5, anchor=CENTER)

reload()

def key_pressed(event):
    if event.keysym == "F5":
        reload()
    elif event.keysym == "Escape":
        root.quit()

root.bind('<Key>', key_pressed)

menu_bar.add_command(label="Yenile", command=reload)
menu_bar.add_command(label="Çıkış", command=root.quit)

root.config(menu=menu_bar)
root.mainloop()

很多地方都说用

mysql-connector-python
代替
mysql-connector
,但我已经用了
mysql-connector-python
。我找不到任何其他解决方案。

sql python-3.x pyinstaller mysql-python mysql-connector
1个回答
0
投票

尝试添加这个。

from mysql.connector.plugins import mysql_native_password

© www.soinside.com 2019 - 2024. All rights reserved.