抱歉,请求的URL ‘http://localhost:8000/index.html’ 导致错误:文件不存在。

huangapple go评论52阅读模式
英文:

[python][js][eel]Sorry, the requested URL 'http://localhost:8000/index.html' caused an error: File does not exist.(the last ask was not answered)

问题

Here is the translated content from your provided text:

"我遇到了一个问题,如果你查看运行Python文件时出现的页面,那么就会弹出这个错误。抱歉,请求的URL 'http://localhost:8000/index.html' 引发了错误:

文件不存在。

好的,如果通过命令行运行,那么:
回溯(最近的调用最后一次)(最新文件在C:\Users\Acer\Desktop\LP\py\Baym\logic.py的第10行),模块><module>
eel.start("index.html")
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\eel_init_.py"的第200行,在"eel.start("index.html")"
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\eel_init_.py"的第191行,在"run_lambda()"
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\bottle.py"的第3175行,在"server.run(app)"
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\bottle_websocket\server.py"的第17行,在"server.serve_forever()"
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\baseserver.py"的第398行,在"self.start()"
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\baseserver.py"的第336行,在"self.init_socket()"
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\pywsgi.py"的第1545行,在"StreamServer.init_socket(self)"
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\server.py"的第180行,在"self.socket = self.get_listener(self.address, self.backlog, self.family)"
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\server.py"的第192行,在"return _tcp_listener(address, backlog=backlog, reuse_addr=cls.reuse_addr, family=family)"
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\server.py"的第288行,在"sock.bind(address)"
文件"C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent_socketcommon.py"的第563行,在"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")

index.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)()
}

好的,我在jeepity聊天中搜索过,没有帮助,我在论坛上搜索过,也没有帮助。最终我来到这里找到了一个解决方案。但这对我没有用(
(在那里,似乎有人说要通过OS模块找到文件名,将其输入到变量中,然后再输入到eel.start()中,正如我所说,这对我没有帮助)"

英文:

I ran into a problem, if you look at the page that runs when you run the python file, then this error pops up. Sorry, the requested URL 'http://localhost:8000/index.html' caused an error:

File does not exist.

ok, if run via cmd, then:
Traceback (most recent call last):
File "C:\Users\Acer\Desktop\LP\py\Baym\logic.py", line 10, in <module>
eel.start("index.html")
File "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", line 191, in run_lambda
btl.run(
File "C:\Users\Acer\AppData\Local\Programs\Python\Python311\Lib\site-packages\bottle.py", line 3175, in run
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, self.family)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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]

my code:

logic.py:

#pip install eel
import eel

eel.init(&quot;web&quot;) 

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

eel.start(&quot;index.html&quot;)

i

ndex.html:

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

main.js:

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

ok, I searched through the jeepity chat, it didn't help, I searched on the forums, it didn't help. Eventually came here and I found a solution. Which didn't work for me(
(There, it seems, people said to find the name of the file through the OS module, enter it into a variable, and already enter it into eel.start(), as I said, it did not help)

答案1

得分: 1

You need to store your static files in the web directory.

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")

When you modify the name of the web directory, you need to synchronously fix the path of init to the name you modified.

英文:

You need to store your static files in the web directory

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 -&gt; eel.init(&#39;web&#39;))
    ├─index.html
    ├─main.js
    ├─css
    └─img

eel.init()

-&gt; def init(path: str, allowed_extensions: List[str] = [&#39;.js&#39;, &#39;.html&#39;, &#39;.txt&#39;, &#39;.htm&#39;,
                                    &#39;.xhtml&#39;, &#39;.vue&#39;], js_result_timeout: int = 10000) -&gt; None:

path : points to your static file directory name


import eel

eel.init(&quot;web&quot;)


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


eel.start(&quot;index.html&quot;)

When you modify the name of the web directory, you need to synchronously fix the path of init to the name you modified

huangapple
  • 本文由 发表于 2023年5月7日 21:47:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76194319.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定