costastf / toonapilib

A library to interact with eneco's "Toon" smart meter via their official api https://api.toon.eu
MIT License
15 stars 11 forks source link

AttributeError: 'list' object has no attribute 'get' #21

Closed frenck closed 5 years ago

frenck commented 5 years ago

Related to conversion in #17, but separated it, since it is a different issue: Currently used toonapilib version: 3.0.6

Traceback (most recent call last):
  File "/Users/frenck/Code/home-assistant/home-assistant/homeassistant/config_entries.py", line 275, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/Users/frenck/Code/home-assistant/home-assistant/homeassistant/components/toon/__init__.py", line 53, in async_setup_entry
    display_common_name=entry.data[CONF_DISPLAY])
  File "/Users/frenck/Code/home-assistant/home-assistant/venv/lib/python3.7/site-packages/toonapilib/toonapilib.py", line 103, in __init__
    self._authenticate()
  File "/Users/frenck/Code/home-assistant/home-assistant/venv/lib/python3.7/site-packages/toonapilib/toonapilib.py", line 150, in _authenticate
    self._get_agreements()
  File "/Users/frenck/Code/home-assistant/home-assistant/venv/lib/python3.7/site-packages/toonapilib/toonapilib.py", line 161, in _get_agreements
    response = requests.get(url, headers=self._headers)
  File "/Users/frenck/Code/home-assistant/home-assistant/venv/lib/python3.7/site-packages/toonapilib/toonapilib.py", line 266, in _patched_request
    response_json.get('fault', {}).get('faultstring', '') == 'Access Token expired']):
AttributeError: 'list' object has no attribute 'get'
costastf commented 5 years ago

That means that the response had a fault that is no longer a dictionary as before but a list so the following get method fails. Can you help out with this, by wrapping it in a try except and printing that fault to see what we are dealing with?

costastf commented 5 years ago

Can you please try 3.0.7? That should fix this error which was introduced because I was trying to be too clever with the token detection.

frenck commented 5 years ago

Thanks @costastf 3.0.7 works for me! 👍