Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
quito96 opened this issue Dec 8, 2022 · 5 comments
Closed

Comments

@quito96
Copy link

quito96 commented Dec 8, 2022

Hi there,

my first run of GETTING_Started Notebook brings errors:

db = detective.db_from_hass_config()

Successfully connected to database mysql://homeassistant:[email protected]: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
Copy link
Owner

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
Copy link
Author

quito96 commented Dec 8, 2022

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
Copy link

jaeti01 commented Mar 10, 2023

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

@bernikr
Copy link

bernikr commented Mar 13, 2023

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
Copy link

ZZDDD commented Mar 29, 2023

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants