【发布时间】:2021-09-20 22:15:00
【问题描述】:
我正在为我的朋友编写一个像 youtube 这样的网站。
但是当我去 http://localhost:2389/watch.v=f4efc9de771d4aba85ee0a88bbce08b9
这是服务器代码:
@app.route('/watch.v=<VideoId>')
def watch(VideoId):
return render_template(
"video.html",
VideoName=video.load_from_id(VideoId),
VideoId=VideoId
)
这是数据库助手:
from sqlite3 import OperationalError
from qrcode import *
from pathlib import Path
import sqlite3
import os
import uuid
DEFAULT_PATH = (os.getcwd() + "\\api\database.db")
connection = sqlite3.connect(DEFAULT_PATH)
cursor = connection.cursor()
cur = cursor
def generateID():
return uuid.uuid4().hex
class video:
def db():
try:
connection = sqlite3.connect(DEFAULT_PATH)
cursor = connection.cursor()
cursor.execute("CREATE TABLE video (name, videoID);")
connection.commit()
print("Creating Database in:", DEFAULT_PATH.upper())
print("[+] Database successfull created!")
except OperationalError:
print("[*] Database allready exists!")
def load_from_id(id):
cursor.execute(f'SELECT name from video WHERE videoID="{id}"')
v = cursor.fetchall()
return str(v).replace("[", "").replace("]", "").replace("'", "").replace("(", "").replace(")", "").strip(",")
class new:
def newVideo(name):
i = generateID()
NewUserData = "INSERT INTO video (name, videoID) VALUES (?, ?)"
cursor.execute(NewUserData, (name, i))
connection.commit()
print(f"[+] Video successfull ceated ({name}, {i}).")
if __name__ == "__main__":
#video.db()
#video.new.new("Test_01")
n = video.load_from_id("f4efc9de771d4aba85ee0a88bbce08b9")
print(n)
这是错误:
Traceback (most recent call last):
File "C:\Users\admin\OneDrive\Desktop\youtube\server.py"
cursor.execute(f'SELECT name from video WHERE videoID="{id}"')
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.
The object was created in thread id 15232 and this is thread id 13568.
我希望有人可以帮助我。
【问题讨论】:
-
请创建一个实际产生错误的最小示例。
-
对不起,我不知道是什么导致了错误