This is the code produce error:
import mysql.connector
import datetime
class Command:
def __init__(self):
mydb = mysql.connector.connect(host='localhost', passwd='1234', user='root', database='customers')
self.mycursor = mydb.cursor()
def execute(self, contest_id, url, Questions):
date = datetime.date.today()
Time = datetime.datetime.now().strftime("%I:%M")
self.mycursor.execute(f"INSERT INTO contest(contest_name, url_tag, Questions, At_date, At_time) VALUES('{contest_id}', '{url}', {Questions}, '{date}', '{Time}')")
我正在运行一个Python代码,我得到以下错误信息。
Traceback (most recent call last):
File "C:\python39\lib\site-packages\mysql\connector\cursor.py", line 518, in execute
if not self._connection:
ReferenceError: weakly-referenced object no longer exists