Describe the problem
I call an exposed python function "load_data_object", and it run fine until the row where I try to call a JS function, "updateTasks" throwing the following error:
Traceback (most recent call last):
File "src\gevent\greenlet.py", line 766, in gevent._greenlet.Greenlet.run
File "C:\Users\*******\AppData\Local\Programs\Python\Python36-32\lib\site-packages\eel\__init__.py", line 257, in _process_message
return_val = _exposed_functions[message['name']](*message['args'])
File "index.py", line 58, in load_data_object
eel.updateTasks({"task_load_data_object": 1})
AttributeError: module 'eel' has no attribute 'updateTasks'
2020-03-28T14:42:40Z <Greenlet at 0xf9ff7a0: _process_message({'call': 1.0315686370569765, 'name': 'load_data_ob, <geventwebsocket.websocket.WebSocket object at 0x0)> failed with Att
ributeError
Code snippet(s)
index.py
import eel
...
@eel.expose()
def load_data_object():
directories = read_data_directory()
data = []
for directory in directories:
reader_images = list(csv_read(f"data/{directory}/images.csv", delimiter=";"))
reader_owners = list(csv_read(f"data/{directory}/owners.csv", delimiter=";"))
reader_extra = list(csv_read(f"data/{directory}/extra.csv", delimiter=";"))
obj = {
"images": reader_images,
"owners": reader_owners,
"extra": reader_extra
}
data.append({directory: obj})
print("updatetasks")
eel.updateTasks({"task_load_data_object": 1})
return data
...
eel.js
import {store} from "./redux/store";
import {update_tasks} from "./redux/actions";
export const eel = window.eel;
eel.expose(updateTasks)
function updateTasks(data){
alert(data)
store.dispatch(update_tasks(data))
}
index.js
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import {Provider} from 'react-redux'
import {store} from './redux/store'
import {eel} from './eel'
import 'normalize.css/normalize.css'
import '@blueprintjs/core/lib/css/blueprint.css'
import '@blueprintjs/icons/lib/css/blueprint-icons.css'
import '@blueprintjs/datetime/lib/css/blueprint-datetime.css'
import 'antd/dist/antd.css'
import './index.css'
eel.set_host('ws://localhost:8888') // development
ReactDOM.render(
<Provider store={store}>
<App/>
</Provider>,
document.getElementById('root')
)
Desktop:
Have you tried running index.py with Windows CMD?
Navigate inside CMD to the project folder and execute the following:
c:\path\to\project> python index.py
I had the same problem when I executed exposed javascript functions in python script within Visual Studio code. There was always an error:
AttributeError: module 'eel' has no attribute 'js_function_name'
Unfortunately, at the moment it only works with CMD for me. Tragically I cannot debug my code this way. If someone has a solution how to configure Visual Studio Code correctly, it is very welcome ;-)
Hi,
Dont understand react much, but can you rename your js file to something other than eel.js (as eel library already uses a js file called eel.js). That might be causing the issue but I am not sure.
Running from command line instead of inside PyCharm have no effect. No effect also renaming the file
Edit:
console.log(eel._exposed_functions)
Show it have the updateTasks function
print("updatetasks")
print("--------------------------------")
print(eel._js_functions) # it print []
print("--------------------------------")
eel.updateTasks({"task_load_data_object": 1})
Show an empty list.
Is your upateTasks function available from window?
Is your eel.js file ever actually included? The './eel' import is the package-provided javascript function. Depending on your directory structure you may need to include it separately (as just 'eel.js'?) or by renaming it as @RahulBadenkal suggested above so it doesn't conflict with the file that is autogenerated.
Changing the configuration with the one in example 7 (07 - CreateReactApp) solved the issue.
Maybe it was a wrong port setting and exposed was not sent to python side
Most helpful comment
Hi,
Dont understand react much, but can you rename your js file to something other than eel.js (as eel library already uses a js file called eel.js). That might be causing the issue but I am not sure.