custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
894 stars 47 forks source link

Blocking Call Error #372

Open Jracon opened 2 years ago

Jracon commented 2 years ago

Very new to all of this, but I am trying to use a python script to interact with an api to translate some text. My code is:

from google_trans_new import google_translator

@service
def translate(text=None, destlang=None):
    translator = google_translator()
    #translate_text = translator.translate(str(text),lang_tgt=destlang)
    translate_text = task.executor(translator.translate, text)
    log.info(translation)

For my requirements I have:

google_trans_new

But when trying to call this service (and/or just on the automatic reload) I get:

2022-07-19 13:39:51 INFO (MainThread) [custom_components.pyscript.global_ctx] Reloaded /config/pyscript/translate.py
2022-07-19 13:39:56 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script
2022-07-19 13:39:56 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service
2022-07-19 13:39:56 ERROR (MainThread) [custom_components.pyscript.file.translate.translate] Exception in <file.translate.translate> line 7:
translate_text = task.executor(translator.translate, text)
^
JSONDecodeError: Extra data: line 1 column 2485 (char 2484)
ALERTua commented 1 year ago

@Jracon could you please update or close the issue? Thank you