#python_script not allowed to import websocket

1 messages · Page 1 of 1 (latest)

jolly geode
#

My python script is suddendly unable to run due to the impossibility of importing websocket:
Failed to perform the action python_script.hyperion_add_remote_source. Error executing script (ImportError): Not allowed to import websocket

marsh berry
#

It is not possible to use Python imports with this integration. If you want to do more advanced scripts, you can take a look at AppDaemon or pyscript

#

You should look into PyScript if you want something more advanced

jolly geode
marsh berry
#

"by accident", perhaps

jolly geode
jolly geode
# marsh berry "by accident", perhaps

I was reading a bit of documentation about the implementation of Websocket APIs in Home Assistant when i stumbled on this chinese doc page where they mentions:

Python - CLI client using asyncws
(NB: in the english version this reference seems to be missing)

So I tried to rewrite my script using asyncio and asyncws instead of websocket, but it doesn't seems that the libraries are shipped with HA anymore:

stdout: ""
stderr: |-
  Traceback (most recent call last):
    File "/config/python_scripts/hyperion_add_remote_source.py", line 3, in <module>
      import asyncws
  ModuleNotFoundError: No module named 'asyncws'
returncode: 1

Any other suggestions before I'll add another integration to my collection?

Home Assistant 中文网

Home Assistant WebSocket API documentation

Home Assistant hosts a WebSocket API at /api/websocket. This API can be used to stream information from a Home Assistant instance to any client that implements WebSockets. We maintain a JavaScript library which we use in our frontend.

foggy matrix
#

suffice to say, use pyscript, you won't have any options with python_scripts unless you look for another loophole (assuming it existed in the first place)

jolly geode
foggy matrix
#

pyscript

#

or write an integration

#

or appdaemon