2

I'm trying to use Eel to make a simple application, but when I run this simple code:

import eel
from os import getcwd
eel.init("web")
eel.start(getcwd() + "\\main.html")

It gives me this error:

Error: 403 Forbidden

If it's important, here is the html code, just a placeholder to test:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <body>
    <h1>Test</h1>
  </body>
</html>

I've tried changing ownership of the file to 'Everyone' and giving full access, but that didn't do anything. I couldn't find anything about this online when I searched for it, so if anyone knows how to fix this, please let me know. TIA!

Fun840
  • 107
  • 1
  • 7
  • 2
    Just say `eel.start("main.html")`. You don't include the whole path in a URL. – Tim Roberts Apr 06 '21 at 21:51
  • @TimRoberts I tried that at first, but when I do that, it gives me the error "Error: 404 Not Found: File does not exist." (the main.html file is in the same directory as the .py file.) this at least says that it found a file. – Fun840 Apr 06 '21 at 21:57
  • @Fun840 Are you certain that "main.html" is in the "web" directory? It should not be in the same directory as the .py file, unless you use that directory when you call `eel.init()`. Try moving main.html to a sub-directory named web, or call `eel.init('.')` – mole1000 Apr 06 '21 at 22:00

2 Answers2

4

This app.py worked for me:

import eel

if __name__ == '__main__':
    eel.init(".")
    eel.start("main.html")

With my directory structure:

/project
  |app.py
  |main.html

With the code you posted, you would need a directory structure like:

/project
  |app.py
  /web
    |main.html
mole1000
  • 161
  • 6
  • Thanks a lot! I was following a tutorial and didn't really understand what I was doing, this fixed it. – Fun840 Apr 06 '21 at 22:25
  • It works for me, but I cannot understand. I tried both relative path and absolute path, but both have no effect – Song Jun 20 '23 at 01:38
0

I just restarted my vs code, and it's worked for me.

Mateo
  • 77
  • 1
  • 8