How can I avoid this error with python apache?:

My code in my programm which is supossed to work is this:

import tkinter as tk
from tkinter import filedialog
from flask import Flask, render_template_string
import threading

app = Flask(__name__)

@app.route('/')
def home():
    return render_template_string(contenido)

def run_server():
    app.run(port=8000)

def abrir_archivo():
    global contenido
    ruta = filedialog.askopenfilename()
    if ruta:
        with open(ruta, 'r') as archivo:
            contenido = archivo.read()
        area_texto.delete('1.0', tk.END)
        area_texto.insert('1.0', contenido)

def guardar_archivo():
    global contenido
    ruta = filedialog.asksaveasfilename()
    if ruta:
        contenido = area_texto.get('1.0', 'end')
        with open(ruta, 'w') as archivo:
            archivo.write(contenido)

def compartir_contenido():
    global contenido
    contenido = area_texto.get('1.0', 'end')
    threading.Thread(target=run_server).start()

ventana = tk.Tk()
ventana.title("Mi Editor de Texto")

ventana.geometry("800x600")

menu = tk.Menu(ventana)
ventana.config(menu=menu)

archivo_menu = tk.Menu(menu)
menu.add_cascade(label="Archivo", menu=archivo_menu)
archivo_menu.add_command(label="Abrir", command=abrir_archivo)
archivo_menu.add_command(label="Guardar", command=guardar_archivo)
archivo_menu.add_command(label="Compartir", command=compartir_contenido)

area_texto = tk.Text(ventana)
area_texto.pack(expand=True, fill='both')

ventana.mainloop()

And the code on my window is this:

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/87/three.js"></script><script>
document.title="Random cube generator."
document.write(".")
document.body.innerHTML=""
document.body.style.backgroundColor="black"
document.body.style.margin="0 0 0 0"
document.body.innerHTML=""
scene=new THREE.Scene()
camera=new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,0.1,10000)
renderer=new THREE.WebGLRenderer()
document.body.appendChild(renderer.domElement)
box=new THREE.BoxGeometry(1,1,1)
box_texture=new THREE.TextureLoader().load("textures/box.jpg")
brick_texture=new THREE.TextureLoader().load("textures/brick.jpg")
stone_texture=new THREE.TextureLoader().load("textures/stone.jpg")
leaves_texture=new THREE.TextureLoader().load("textures/leaves.jpg")
box_material=new THREE.MeshLambertMaterial({color:"rgb(255,255,255)",map:box_texture})
brick_material=new THREE.MeshLambertMaterial({color:"rgb(255,255,255)",map:brick_texture})
stone_material=new THREE.MeshLambertMaterial({color:"rgb(255,255,255)",map:stone_texture})
leaves_material=new THREE.MeshLambertMaterial({color:"rgb(255,255,255)",map:leaves_texture})
k={}
cube={}
onkeydown=onkeyup=(e)=>{k[e.keyCode]=e.type=="keydown"}
scene.add(cube)
light=new THREE.PointLight(0xffffff,1,100)
scene.add(light)
light.position.z=10
camera.position.z=10
render=()=>{
renderer.setSize(innerWidth,innerHeight)
camera.aspect=innerWidth/innerHeight
camera.updateProjectionMatrix()
requestAnimationFrame(render)
renderer.render(scene,camera)
}
render()
g=(x,y,z)=>{
i=Math.random()
if(Math.random()<1/2){
if(Math.random()<1/2){
cube[i]={s:new THREE.Mesh(box,box_material)}
}else{
cube[i]={s:new THREE.Mesh(box,brick_material)}
}
}else{
if(Math.random()<1/2){
cube[i]={s:new THREE.Mesh(box,stone_material)}
}else{
cube[i]={s:new THREE.Mesh(box,leaves_material)}
}
}
cube[i].s.position.set(x,y,z)
scene.add(cube[i].s)
}
for(x=-100;x<100;x++){
for(y=-100;y<100;y++){
for(z=-75;z<4;z++){
if(Math.random()<0.05){
g(x,y,z)
}}}}
</script>

And it shows me this error when i execute it on localhost:8000:

And I dont know how to place the textures inside my app. Any idea? Thanks anyway.

Oka, i solved it with this code:

import subprocess
import os

def start_local_server(port=8000):
try:
# Obtiene la ruta del directorio actual
current_directory = os.path.dirname(os.path.abspath(file))
# Ejecuta el comando para iniciar el servidor web local en el directorio actual
subprocess.Popen([“python”, “-m”, “http.server”, str(port), “–directory”, current_directory])
print(f"Servidor web local iniciado en el puerto {port} para el directorio {current_directory}.“)
except FileNotFoundError:
print(“Error: Python no está instalado o no se encuentra en el PATH.”)
except Exception as e:
print(f"Error al iniciar el servidor: {e}”)

if name == “main”:
start_local_server()