jcgoette / baby_buddy_homeassistant

This custom integration provides sensors for Baby Buddy API endpoints.
MIT License
64 stars 30 forks source link

JSON decoder error after installation #5

Closed thebino closed 3 years ago

thebino commented 3 years ago

Right after installation of babybuddy and the sensor via hacs, this error showed up. Perhaps it has something to do with the new installation of babybuddy and an empty database after installation.


Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/babybuddy/sensor.py", line 42, in setup_platform
    for entity in baby_buddy_data.entities_get():
  File "/config/custom_components/babybuddy/sensor.py", line 132, in entities_get
    children = session.get("children/").json()
  File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
jcgoette commented 3 years ago

Just tried with a fresh babybuddy and home assistant development environment and didn't get this. Will you post the relevant portion of your config.yml also?

thebino commented 3 years ago

I tried, with/without port

sensor:
 - platform: babybuddy
   address: 172.17.3.1
   api_key: !secret babybuddy_api_key
jcgoette commented 3 years ago

Ah, I think I have reproduced the issue.

Did you configure Baby Buddy ALLOWED_HOSTS to be accessible to your Home Assistant host?

thebino commented 3 years ago

yes, the ALLOWED_HOST is set correctly. It cannot connect, since the instance does not provide a ssl certificate

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 573, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='172.17.3.1', port=7000): Max retries exceeded with url: /api/children/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)')))
jcgoette commented 3 years ago

Yup, you need to use an HTTPS address currently. I may implement fallback to HTTP in conjunction with PR #2 to issue a warning.