pyscript icon indicating copy to clipboard operation
pyscript copied to clipboard

Error on call http://172.30.32.1:8123/api/config: Watchdog found a problem with Home Assistant API!

Open dE1l opened this issue 3 years ago • 1 comments

I'm start this script /config/pyscript/expample_spoti.py:

import os
import sys

from dotenv import load_dotenv

import spotipy
from spotipy.oauth2 import SpotifyOAuth

@service
def spotipy_me():
    """sptipy_world example using pyscript."""

    path = sys.path[1]+'/pyscript/.env'
    load_dotenv(path)

    sp = spotipy.Spotify(auth_manager=SpotifyOAuth())

    device_id = os.getenv('SPOTIPY_DEVICE_ID')
    sp.pause_playback(device_id)

with /config/pyscript/requirements.txt :

spotipy
python-dotenv

and it's broken Home Assistant - UI not response some minutes

22-01-13 10:29:56 ERROR (MainThread) [supervisor.homeassistant.api] Error on call http://172.30.32.1:8123/api/config: 22-01-13 10:29:56 ERROR (MainThread) [supervisor.misc.tasks] Watchdog found a problem with Home Assistant API!

dE1l avatar Jan 13 '22 07:01 dE1l

It's likely that spotipy does blocking I/O, which stalls the main event loop. See the docs here.

I'd recommend using async-spotify, which is designed for non-blocking async operation, or some other package that supports async operation.

craigbarratt avatar Jan 13 '22 08:01 craigbarratt