robmarkcole / HASS-data-detective

Explore and analyse your Home Assistant data
https://data.home-assistant.io/
MIT License
184 stars 36 forks source link

TypeError: the JSON object must be str, bytes or bytearray, not NoneType #148

Closed quito96 closed 1 year ago

quito96 commented 1 year ago

Hi there,

my first run of GETTING_Started Notebook brings errors:

db = detective.db_from_hass_config()

Successfully connected to database mysql://homeassistant:pwd@192.168.2.40:3306/homeassistant?charset-utf8mb4 There are 381 entities with data

Okay, then start Sequence Popular entities and the error occures:


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [15], line 21
     18     continue
     20 try:
---> 21     event_data = json.loads(event.event_data)
     22 except ValueError:
     23     continue

File /usr/lib/python3.9/json/__init__.py:339, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    337 else:
    338     if not isinstance(s, (bytes, bytearray)):
--> 339         raise TypeError(f'the JSON object must be str, bytes or bytearray, '
    340                         f'not {s.__class__.__name__}')
    341     s = s.decode(detect_encoding(s), 'surrogatepass')
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):

TypeError: the JSON object must be str, bytes or bytearray, not NoneType

How can i solve it?

BR

robmarkcole commented 1 year ago

Hmm to debug need to understand what is wrong with the data you are trying to access. You can see the queries being run in https://github.com/robmarkcole/HASS-data-detective/blob/master/detective/core.py so try and debug where this error is coming from

quito96 commented 1 year ago

Hi, I started the core.py in jupyter lab (right?) and get this:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In [1], line 10
      7 import pandas as pd
      8 from sqlalchemy import create_engine, text
---> 10 from . import config, functions
     13 def db_from_hass_config(path=None, **kwargs):
     14     """Initialize a database from HASS config."""

ImportError: attempted relative import with no known parent package
jaeti01 commented 1 year ago

I am having the exact same issue. Did anyone get this solved? Thanks!

bernikr commented 1 year ago

I have the same problem. Also the fetch_all_sensor_data function returns None for every sensor in the last_updated field. I think both of these errors come from a recent change in database schema. last_updated for example was replaced by last_updated_ts.

ZZDDD commented 1 year ago

I have the same problem. Also the fetch_all_sensor_data function returns None for every sensor in the last_updated field. I think both of these errors come from a recent change in database schema. last_updated for example was replaced by last_updated_ts. @bernikr

Wow, thanks! I just substituted all the occurrences of last_updated into last_updated_ts in all code and reinstalled the detective and it worked! Now, Instead of getting None for the the field you get timestamp numbers. Conversion can be easily done by: df['last_updated_ts'] = pd.to_datetime(df['last_updated_ts'], unit='s')