Пытаюсь подключить Python к HTML с помощью eel.Всё сделал правильно, и по уроку , и по документации.Но когда запускаю приложение,написано что Сайт localhost не позволяет установить соединение.
Python
import eel
eel.init("static")
@eel.expose
def say_hello_from_js(x):
print(f"Hello from {x}")
eel.say_hello_from_python("Python!")
eel.start("index.html", size=(500, 500))
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Eello World!</h1>
<p>Congrats, Eel seems to work fine</p>
<script src="/eel.js"></script>
<script src="/script.js"></script>
</body>
</html>
js
eel.say_hello_from_js("Javascript!");
eel.expose(say_hello_from_python)
function say_hello_from_python(x){
console.log("Hello from {}".replace("{}", x))
}
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
mvincenzi96 opened this issue
Jul 11, 2019
· 20 comments
Comments
Hey ya, I know this issue has probably been dealt with before, however I can’t find any proper workarounds to it.
I am getting this message:
`Error: 404 Not Found
Sorry, the requested URL ‘http://localhost:8000/main.html’ caused an error:
File does not exist.`
Everytime I run a test eel project.
First I had issues with Python displaying a osError because some other program was using port 8000. After I killed that task to leave that port free for eel, it only showed me the message you can see above.
Here’s the code:
eeltest.py
`import eel
eel.init(‘web’)
eel.start(‘main.html’)`
main.html
<p>Hola</p>
Any help will be very appreciated in advance.
Let me see, the issue here is that probably you forgot to create the folder «web» inside your Eel project. wasn’t it this?
Nope. Creating that folder was the first thing I did.
However, I found a workaround. It seems like when I execute the .py file
from Visual Studio Code or CMD, it shows this error. Nevertheless, if I run
it from IDLE, everything works properly.
Not sure of why does it have that behavior but, it works for now if its
executed from IDLE.
…
Same Problem.
Eel worked before, but when i run the second time suddenly it broken.
Although cleaning the chrome cache, it doesn’t work anymore
@mvincenzi96 Are you able to share the full code you’re using, e.g. by sharing a link to your git repository? This will let me test this more easily to confirm what’s going wrong and help you.
It seems to be cache related. Try running your program after changing to the program directory, then try running the program from somewhere else. If you clear the cache then you’ll probably get the same error.
@samuelhwilliams https://github.com/axl3blaz3/Botx2 , this only works on python IDLE and wouldn’t work with python.exe , since i am integrating it with automation anywhere RPA tool i need it through python.exe.
Edit:
problem is not with the code, even sample(basic) code is not working, i reinstalled chrome,python and eel still no help.. maybe something with port listening …
@samuelhwilliams @ChrisKnott I too face the same issue. PyInstaller works, web
folder is there, but it seems to throw the same error as the OP posted here. I hope this issue is resolved soon.
Here is the screenshot of my directories, I hope it helps!
The directory is the same, as suggested in the README.md .
I’m using python3 -m eel app_main.py web --onefile
to build my files.
I found out the solution, kill all the processes running on that port. I didn’t get any error because it crashed on startup.
Anyone who is stuck here, the fix is:
- Kill the processes on the port by using
fuser -k [port_name]/tcp
. - Build the file using the steps mentioned here.
- Run the executable again! It works now!
This is not related to the cache as mentioned above, I tried clearing the cache as well keeping the cache.
@mvincenzi96 Are you able to share the full code you’re using, e.g. by sharing a link to your git repository? This will let me test this more easily to confirm what’s going wrong and help you.
#168 (comment)
It seems to be cache related. Try running your program after changing to the program directory, then try running the program from somewhere else. If you clear the cache then you’ll probably get the same error.
#168 (comment)
I already had have the same problem and i was be able to solved. The way i’ve solved is just change the line:
eel.init('web')
to the absolute path, like
eel.init('C:/.../web')
where my web folder is
I hope that helps!
After the new update, you need to provide the location of html file.
For your program you can do:
eel.start(«web/main.html»)
It worked for me
Hope it works for you.
My issue was that i had a python exe that I already built with pyinstaller that was running in the background, even though it was closed out. So it was taking up the port and refusing any new connections. Once i opened task manager to kill the exe I was able to run it fine.
Hope this helps!
I have found solution to this particular problem : ) — just do two things first make sure that your main html file name is index.html and other is that the file must exist in the specific location where you have specified in eel.init("foldername")
function (☞゚ヮ゚)☞ and the problem is solved
Just change it to any other port instead of 8000.
eel.start («index.html», port = your port)
import eel
import os
Set web files folder
eel.init(f'{os.path.dirname(os.path.realpath(file))}/web’)
Thanks jpanzolaa, using an absolute path was the solution for me to
When I use eel.init(‘web’) it got the 404 error, so i used an absolute Path but then i got the 403 error: access denied. Can someone explain? I allready removed the catch etc.
import eel import os
Set web files folder
eel.init(f'{os.path.dirname(os.path.realpath(file))}/web’)
I am using PyCharm which establishes a venv folder that I mistakingly stored my «web» folder in.
This made the file path of my main.py file «$project» but my web folder was in «$project/venv/web» so I had to move my web folder up one level in order for the realpath to work
@Sergomen
Просто делай добро и оно вернётся
Я вот пробую осилить библиотеку eel в Питоне но получаю ошибку :
Uncaught ReferenceError: eel is not defined
at all (main.html:24)
at main.html:28
скрин
main.py
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import eel
import eel.browsers
@eel.expose
def test():
return "hell"
eel.init("web")
eel.browsers.set_path('chrome', '.\res\App\Chrome-bin\chrome.exe')
eel.start("main.html",size=(700,700),mode="chrome")
main.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Language' content='ua'>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<meta name='viewport' content='width = device-width,height = device-height, initial-scale = 1'>
<style type="text/css">
body{
background: black;
color:white;
}
</style>
<script scr="eel.js"></script>
</head>
<body>
<p id="text">text</p>
<script>
function all() {
var t = document.getElementById("text");
var text = eel.test(); //-- 24 -
t.innerHTML = text;
}
all(); //-- 28 -
</script>
</body>
</html>
Что я не так сделал?
-
Вопрос заданболее двух лет назад
-
355 просмотров
Что я не так сделал?
scr вместо src
<script src="eel.js"></script>
Пригласить эксперта
Попробуй eel вот так подключить:
<script type="text/javascript" src="/eel.js"></script>
-
Показать ещё
Загружается…
04 июн. 2023, в 01:35
1500 руб./за проект
04 июн. 2023, в 01:25
40000 руб./за проект
03 июн. 2023, в 23:42
1500 руб./за проект
Минуточку внимания
Hello! I’m attempting to use Electron with Eel in the latest versions.
The ‘mode=’electron» option only yielded me this:
Script:
import eel
eel.init('web')
eel.start('index.html', size=(800, 600), block=False, mode='electron')
while True:
eel.sleep(10)
Error:
Traceback (most recent call last):
File "C:UsersUserAppDataLocalPackagesCanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgscLocalStaterootfsrootnexitnew.py", line 7, in <module>
eel.start('index.html', size=(800, 600), block=False, mode='electron')
File "C:UsersUserAppDataLocalProgramsPythonPython39-32libsite-packageseel__init__.py", line 158, in start
show(*start_urls)
File "C:UsersUserAppDataLocalProgramsPythonPython39-32libsite-packageseel__init__.py", line 186, in show
brw.open(start_urls, _start_args)
File "C:UsersUserAppDataLocalProgramsPythonPython39-32libsite-packageseelbrowsers.py", line 59, in open
path = browser_module.find_path()
File "C:UsersUserAppDataLocalProgramsPythonPython39-32libsite-packageseelelectron.py", line 18, in find_path
return os.path.join(bat_path, r'..node_moduleselectrondistelectron.exe')
File "C:UsersUserAppDataLocalProgramsPythonPython39-32libntpath.py", line 78, in join
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType
I assumed the «NoneType» was from the lack of a path to my electron installation, so I attempted a custom directory:
Script:
import eel
eel.init('web')
eel.start('index.html', size=(800, 600), block=False, mode='custom', cmdline_args=['node_modules/electron/dist/electron.exe', '.'])
while True:
eel.sleep(10)
The error now came in a popup alert box: (screenshot)
ERROR LAUNCHING APP
Unable to find Electron app at
C:UsersUserAppDataLocalPackagesCanonicalGroupLimited.UbuntuonWindow...nexit
Cannot find module
'C:UsersUserAppDataLocalPackagesCanonicalGroupLimited.UbuntuonWindow...main.js'.
Please verify that the package.json has a valid "main" entry
Any input is appreciated, this is a wonderful little library and I only hope to see it grow!
Here’s my directory tree:
- /Nexit/
- /node_modules/
- (all other node modules)
- /electron/
- /dist/
- electron.exe
- /dist/
- /web/
- main.html
- main.js
- package.json
- script.py
- /node_modules/
My package.json:
{
"name": "nexit",
"version": "0.0.0",
"main": "main.js",
"devDependencies": {
"electron": "^2.0.0"
}
}
My main.js:
console.log("Hello world!");
const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
let mainWindow
function createWindow () {
mainWindow = new BrowserWindow({width: 800, height: 600})
mainWindow.loadURL('http://localhost:8000/main.html');
mainWindow.on('closed', function () {
mainWindow = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
app.quit()
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow()
}
})
My HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Nexit</title>
<script type="text/javascript" src="/eel.js"></script>
<script type="text/javascript" src="main.js"></script>
<script>
eel.expose(jav);
function jav(a, b) {
console.log(a + b);
}
</script>
<head></head>
<body><p>text</p></body>
</html>
SPECS:
- OS: Windows 10
- Python v: 3.9.0
- Eel v: 0.14.0
По адресу
не находит нужного файла, пробовал даже указывать полный адресс до eel.js, но не помогло.
Вот код (Html & js):
<!DOCTYPE html>
<html>
<head>
<title>test aplication</title>
<link rel="icon" type="image/png" href="icon.png">
<script type="text/javascript" scr="C:UsersArtyrAppDataLocalProgramsPythonPython38-32Libsite-packageseeleel.js"></script>
</head>
<body>
<textarea id="num1"></textarea>
<textarea id="num2"></textarea>
<textarea id="ans"></textarea>
<button type="button" id="add" onclick="addition()">THIS IS BUTTON</button>
<!--<script type="text/javascript" scr="D:ProjectsEelwebmain.js"></script>-->
<script type="text/javascript">
eel.expose(addition);
function addition(){
var data1 = document.getElementById('num1').value
var data2 = document.getElementById('num2').value
eel.add(data1, data2)(callBack)
}
function callBack(result){
document.get.getElementById('ans').value = result
}
</script>
</body>
</html>
Код (python):
import eel eel.init('web') @eel.expose def add(data1, data2): num1 = int(data1) num2 = int(data2) result = num1 + num2 return result eel.start('index.html', size = (700, 700))
P.S: Я не предумывал, этот код, а взял его из одного гайда
Ответы (1 шт):
С:UsersArtyrAppDataLocalProgramsPythonPython38-32Libsite-packageseeleel.js
— это не правильный путь.
Положите eel.js
рядом с index.html
и подключайте так:
<script type="text/javascript" scr="/eel.js"></script>
→ Ссылка