Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
属性错误:';元组';对象没有属性';编码';-MySQL.connector.Python_Python_Mysql_Database - Fatal编程技术网

属性错误:';元组';对象没有属性';编码';-MySQL.connector.Python

属性错误:';元组';对象没有属性';编码';-MySQL.connector.Python,python,mysql,database,Python,Mysql,Database,好的 这就是错误所在 Traceback (most recent call last): File "C:/Users/Mandem/PycharmProjects/untitled/Pranks/Lib/site-packages/Ada.py", line 161, in <module> mycursor.execute(updaterScoren) File "C:\Users\Mandem\AppData\Local\Prog

好的 这就是错误所在

Traceback (most recent call last):
  File "C:/Users/Mandem/PycharmProjects/untitled/Pranks/Lib/site-packages/Ada.py", line 161, in <module>
    mycursor.execute(updaterScoren)
  File "C:\Users\Mandem\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\cursor.py", line 546, in execute
    stmt = operation.encode(self._connection.python_charset)
AttributeError: 'tuple' object has no attribute 'encode'

Process finished with exit code 1
我是这样运行的:

# MySQL Commands
        updaterScoren = "UPDATE bois SET pinkode_brugt = pinkode_brugt + 1 WHERE id = %s", (f,)

        myresult = mycursor.fetchall()

        row_count = mycursor.rowcount
        print(myresult)
        print("number of affected rows: {}".format(row_count))
        if row_count == 1:

            print(row_count)
            print(app.timerValue)
            while (i != app.timerValue) and (i <= app.timerValue) and (doorButton != 1) and (app.stopButton != 1):
                print('%.2f' % i)
                i = i + 0.01
                timeLeft = app.timerValue - i
                iTwo = app.timerValue
                print("THIS IS X", app.timerValue)
                time.sleep(0.01)
            # Hvis spillet stoppes, or i ikke når timerens slutværdi, vil scoren gemmes
            if (i != app.timerValue):
                score = i
                print("Dette er dit resultat: {}".format('%.2f' %score))
                mycursor.execute(updaterScoren)
#MySQL命令
updaterScoren=“UPDATE bois SET pinkode\u brugt=pinkode\u brugt+1,其中id=%s”,(f,)
myresult=mycursor.fetchall()
row\u count=mycursor.rowcount
打印(myresult)
打印(“受影响的行数:{}”。格式(行计数))
如果行计数=1:
打印(行数)
打印(应用程序timerValue)
而(i!=app.timerValue)和(i无:
self.master=tk.tk()
自我控制(“0+0”)
self.master=tk.Label(self.root,bg=“黑色”,fg=“红色”)
self.timer.grid(行=1,列=2)
self.master.mainloop()
Tkinter类(线程。线程):
定义初始化(自):
threading.Thread.\uuuuu init\uuuuuu(自)
self.daemon=True
self.root=0
self.entry=0
self.label=0
self.button=0
self.timerValue=0
self.stopButton=0
self.start()
def运行(自)->0:
self.root=tk.tk()
#tkinter代码在这里
self.root.geometry(“+2+0”)
self.root.config(background=“black”)
self.label=tk.label(self.root,bg=“白色”,fg=“黑色”,font=(“Fixedsys”,28))
self.entry=tk.entry(self.root,bg=“白色”,fg=“黑色”,font=(“Fixedsys”,28))
self.stopTiden=tk.按钮(self.root,bg=“red”,fg=“white”,text=“Stop Spillet”,command=self.stopTid)
self.startTiden=tk.按钮(self.root,bg=“绿色”,fg=“白色”,text=“启动溢出”,command=self.startTid)
self.timerDisplay=tk.Label(self.root,bg=“black”,fg=“red”,text=“Ceci n'est pas unie timer”)
self.timerDisplay.grid(行=2,列=50)
self.startTiden.grid(行=0,列=1)
self.stopTiden.grid(行=0,列=10)
self.entry.grid(行=1,列=1)
self.label.grid(行=1,列=10)
self.root.bind(“,self.read)
self.root.mainloop()
def显示时间(自我):
self.timerDisplay.config(text=i)
def读取(自身、事件):
key=event.keysym
尝试:
如果键==“Return”:
self.getA()
self.visTid()
除:
self.fejltivalg()
def STARTID(自身):
self.stopButton=0
def getA(自我):
self.timerValue=float(self.entry.get().format(“%.2f”,1.23456))
打印(self.timerValue)
返回self.timerValue
def stopTid(自身):
self.stopButton=1
def visTid(自身):
self.label.config(text=“Det her er timerens slutværdi:{}”.format(self.timerValue))
def fejlTidvalg(自身):
self.label.config(text=“FEJL-Vælg Venligst Et Tal”)
app=Tkinter()
stopTiden=0
#登录til数据库
mydb=mysql.connector.connect(
host=“****”,
user=“****”,
password=“*******”,
database='mydatabase',
auth\u plugin='mysql\u native\u password'
)
门按钮=0
而(门按钮!=1):
stopButton=app.stopButton
timerValue=app.timerValue
iTwo=时间值
门按钮=0
i=0.00
mycursor=mydb.cursor()
def倒计时(i):
而我:
分,秒=divmod(t,60)
计时器={:02d}:{:02d}。格式(分钟,秒)
打印(计时器,结束=“\r”)
时间。睡眠(1)
t-=1
#Servodøren skalåbnes她我是denne kode
而(app.stopButton!=1):
#平科登酒店
f=int(输入(
“Kodeord-bemærkher,kodeordene er pinkoderne fra min egen数据库,bare indtast en værdi mellem 1-6”))
mycursor.execute(“选择id、地址、名称、pinkode_brugt、来自bois的分数,其中id=%s”,(f,))
#MySQL命令
updaterScoren=“UPDATE bois SET pinkode\u brugt=pinkode\u brugt+1,其中id=%s”,(f,)
myresult=mycursor.fetchall()
row\u count=mycursor.rowcount
打印(myresult)
打印(“受影响的行数:{}”。格式(行计数))
如果行计数=1:
打印(行数)
打印(应用程序timerValue)
而(i!=app.timerValue)和(i
updaterScoren=“UPDATE bois SET pinkode\u brugt=pinkode\u brugt+1,其中id=%s”,(f),)
updaterScoren=“UPDATE bois SET pinkode\u brugt=pinkode\u brugt+1,其中id=%s”%f


当您不正确地使用格式变量时,是否应该执行此操作

您是否可以尝试打印变量
操作
?您将其视为字符串,但在某个地方它被返回为tupleI did“print(UpdatesCoren)”,并且它返回了此
(“UPDATE-bois SET pinkode_brugt=pinkode_brugt+1,其中id=%s',(3,))
此命令在python3.86中运行,但您必须检查f,它看起来不正确right@nbk在Python3.86中运行哪个命令?我的?如果是,那意味着什么?同样,它是错误的,我更改了它,它在语法上工作,但在语义上它仍然没有包含值,也没有用我的变量score(score=I)替换“mysql”-score。是的,我在您的代码中没有看到您检查有效的select是否有该select的答案。因此,我将检查它是否得到非空的答复。非常感谢您的帮助,Himanshu。您的解决方案确实修复了我的语法错误。问题是,现在我有一个语义错误。值“pinkode_brugt”不更新/增加。你知道为什么吗?另外,你能解释一下,代码中的变化是什么,这样我以后可以避免这个错误吗?
# MySQL Commands
        updaterScoren = "UPDATE bois SET pinkode_brugt = pinkode_brugt + 1 WHERE id = %s", (f,)

        myresult = mycursor.fetchall()

        row_count = mycursor.rowcount
        print(myresult)
        print("number of affected rows: {}".format(row_count))
        if row_count == 1:

            print(row_count)
            print(app.timerValue)
            while (i != app.timerValue) and (i <= app.timerValue) and (doorButton != 1) and (app.stopButton != 1):
                print('%.2f' % i)
                i = i + 0.01
                timeLeft = app.timerValue - i
                iTwo = app.timerValue
                print("THIS IS X", app.timerValue)
                time.sleep(0.01)
            # Hvis spillet stoppes, or i ikke når timerens slutværdi, vil scoren gemmes
            if (i != app.timerValue):
                score = i
                print("Dette er dit resultat: {}".format('%.2f' %score))
                mycursor.execute(updaterScoren)
import threading
import tkinter as tk
import pip
import time
import mysql.connector
from time import sleep




# NY THREAD(s), der kan vise scoreboarden på en skærm.
class Timer(threading.Thread):
    def _init_(self):
        threading.Thread._init_(self)
        self.label = 0
        global score


    def run(self) -> None:
        self.master = tk.Tk()

        self.master.gemoetry("+0+0")

        self.master = tk.Label(self.root, bg = "black", fg = "red")

        self.timer.grid(row = 1, column = 2)

        self.master.mainloop()


class Tkinter(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.daemon = True
        self.root = 0
        self.entry = 0
        self.label = 0
        self.button = 0
        self.timerValue = 0
        self.stopButton = 0

        self.start()

    def run(self) -> 0:
        self.root = tk.Tk()

        # tkinter code goes here
        self.root.geometry("+2+0")
        self.root.config(background="black")

        self.label = tk.Label(self.root, bg="white", fg="black", font=("Fixedsys", 28))
        self.entry = tk.Entry(self.root, bg="white", fg="black", font=("Fixedsys", 28))
        self.stopTiden = tk.Button(self.root, bg="red", fg="white", text="Stop Spillet", command=self.stopTid)
        self.startTiden = tk.Button(self.root, bg="green", fg="white", text="Start Spillet", command=self.startTid)

        self.timerDisplay = tk.Label(self.root, bg="black", fg="red", text="Ceci n'est pas une timer")

        self.timerDisplay.grid(row=2, column=50)
        self.startTiden.grid(row=0, column=1)
        self.stopTiden.grid(row=0, column=10)
        self.entry.grid(row=1, column=1)
        self.label.grid(row=1, column=10)

        self.root.bind("<KeyPress>", self.read)
        self.root.mainloop()

    def displayTime(self):
        self.timerDisplay.config(text=i)

    def read(self, event):
        key = event.keysym
        try:
            if key == "Return":
                self.getA()
                self.visTid()
        except:
            self.fejlTidvalg()

    def startTid(self):
        self.stopButton = 0

    def getA(self):
        self.timerValue = float(self.entry.get().format("%.2f", 1.23456))
        print(self.timerValue)
        return self.timerValue

    def stopTid(self):
        self.stopButton = 1

    def visTid(self):
        self.label.config(text="Det her er timerens slutværdi: {}".format(self.timerValue))

    def fejlTidvalg(self):
        self.label.config(text="FEJL -Vælg Venligst Et Tal")


app = Tkinter()

stopTiden = 0

# Login til databasen
mydb = mysql.connector.connect(
    host="****",
    user="****",
    password="*****",
    database='mydatabase',
    auth_plugin='mysql_native_password'
)

doorButton = 0

while (doorButton != 1):
    stopButton = app.stopButton
    timerValue = app.timerValue
    iTwo = timerValue
    doorButton = 0
    i = 0.00
    mycursor = mydb.cursor()


    def countdown(i):

        while i:
            mins, secs = divmod(t, 60)
            timer = '{:02d}:{:02d}'.format(mins, secs)
            print(timer, end="\r")
            time.sleep(1)
            t -= 1


    # Servodøren skal åbnes her i denne kode
    while (app.stopButton != 1):
        # Indtast Pinkoden
        f = int(input(
            "Kodeord - bemærk her, at kodeordene er pinkoderne fra min egen database, bare indtast en værdi mellem 1-6"))
        mycursor.execute("SELECT id,adresse,name,pinkode_brugt,score FROM bois WHERE id=%s", (f,))

        # MySQL Commands
        updaterScoren = "UPDATE bois SET pinkode_brugt = pinkode_brugt + 1 WHERE id = %s", (f,)

        myresult = mycursor.fetchall()

        row_count = mycursor.rowcount
        print(myresult)
        print("number of affected rows: {}".format(row_count))
        if row_count == 1:

            print(row_count)
            print(app.timerValue)
            while (i != app.timerValue) and (i <= app.timerValue) and (doorButton != 1) and (app.stopButton != 1):
                print('%.2f' % i)
                i = i + 0.01
                timeLeft = app.timerValue - i
                iTwo = app.timerValue
                print("THIS IS X", app.timerValue)
                time.sleep(0.01)
            # Hvis spillet stoppes, or i ikke når timerens slutværdi, vil scoren gemmes
            if (i != app.timerValue):
                score = i
                print("Dette er dit resultat: {}".format('%.2f' %score))
                mycursor.execute(updaterScoren)


            else:
                print("Ingen point")
                mycursor.execute()


        i = 0
    # Her skal du tilføje i til den ID's row, der lige har åbnet via sin pinkode. Så er du stort set færdig! :D