[python][js][eel]对不起,请求的URL 'http://localhost:8000/index.html'导致错误:文件不存在,(最后一个问题没有得到回答)

bqjvbblv  于 2023-05-12  发布在  Python
关注(0)|答案(1)|浏览(396)

我遇到了一个问题,如果你看看运行python文件时运行的页面,然后弹出这个错误。对不起,请求的URL "http://qqq.com:8000/index.html"导致错误:
文件不存在。
ok,如果通过cmd运行,则:追溯(最近一次调用):文件“C:\Users\Acer\Desktop\LP\py\Baym\logic.py ",line 10,in eel. start(" index.html ")文件" C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\eel_* init 。py ",line 200,in start run_lambda()File" C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\eel init *_。py ",第191行,在run_lambda www.example.com中(文件" C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\bottle.py",line 3175,in run www.example.com(app)File" C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\bottle_websocket\server.py",line 17,in run server. serve_forever()文件" C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\baseserver.py",line 398,in serve_forever self. start()文件" C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\baseserver.py",第336行,在start self中。init_socket()文件" C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\pywsgi.py",line 1545,in init_socket StreamServer. init_socket(self)文件" C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\server.py",line 180,in init_socket self. socket = self. get_listener(self.地址,自我。积压,btl.run[WinError 10048] server.run (app) File "C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\bottle_websocket\server.py", line 17, in run server.serve_forever() File "C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\baseserver.py", line 398, in serve_forever self.start() File "C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\baseserver.py", line 336, in start self.init_socket() File "C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\pywsgi.py", line 1545, in init_socket StreamServer.init_socket(self) File "C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\server.py", line 180, in init_socket self.socket = self.get_listener(self.address, self.backlog, www.example.com ) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\server.py", line 192, in get_listener return _tcp_listener(address, backlog=backlog, reuse_addr=cls.reuse_addr, family=family) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\server.py", line 288, in _tcp_listener sock.bind(address) File "C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent_socketcommon.py", line 563, in bind return self._sock.bind(address) ^^^^^^^^^^^^^^^^^^^^^^^^ OSError: [WinError 10048]
我的代码:
logic.py:

#pip install eel
import eel

eel.init("web") 

@eel.expose 
def ret(x):
    print(x)

eel.start("index.html")

i

ndex.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="/eel.js"></script>
    <script type="text/javascript" src="main.js"></script>
    <title>s</title>
</head>
<body>
    <input type="text" id="text">
    <button onclick="data"></button>
</body>
</html>

main.js:

function data(){
    var x = document.getElementById("text").value
    eel.ret(x)()
}

好吧,我搜索了吉普车聊天,它没有帮助,我在论坛上搜索,它没有帮助。最后我来到这里,找到了解决办法。这对我来说不起作用((在那里,似乎人们说要通过OS模块找到文件的名称,将其输入到变量中,并且已经将其输入到eel. start()中,正如我所说,它没有帮助)

xxslljrj

xxslljrj1#

您需要将静态文件存储在Web目录中
https://github.com/python-eel/Eel#starting-the-app
Suppose you put all the frontend files in a directory called web, including your start page main.html, then the app is started like this;
eel.init('web ')

app
├─logic.py
└─web(path name -> eel.init('web'))
    ├─index.html
    ├─main.js
    ├─css
    └─img
eel.init()

-> def init(path: str, allowed_extensions: List[str] = ['.js', '.html', '.txt', '.htm',
                                    '.xhtml', '.vue'], js_result_timeout: int = 10000) -> None:

path : points to your static file directory name
import eel

eel.init("web")

@eel.expose
def ret(x):
    print(x)

eel.start("index.html")

当您修改Web目录的名称时,您需要将init的路径同步固定为您修改的名称

相关问题