arraylabs / pymyq

Python wrapper for MyQ API
MIT License
112 stars 42 forks source link

UnboundLocalError: local variable 'err' referenced before assignment #57

Closed komailo closed 3 years ago

komailo commented 3 years ago

Using Home Assistant 2020.12.1 that comes with pymyq==2.0.11. Unable to configure MyQ integration and getting this error.

2020-12-26 14:20:52 WARNING (MainThread) [pymyq.api] Device update failed; trying again in 2 seconds
2020-12-26 14:20:54 WARNING (MainThread) [pymyq.api] Device update failed; trying again in 4 seconds
2020-12-26 14:20:58 WARNING (MainThread) [pymyq.api] Device update failed; trying again in 5 seconds
2020-12-26 14:21:04 ERROR (MainThread) [homeassistant.components.myq.config_flow] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/myq/config_flow.py", line 50, in async_step_user
    info = await validate_input(self.hass, user_input)
  File "/usr/src/homeassistant/homeassistant/components/myq/config_flow.py", line 30, in validate_input
    await pymyq.login(data[CONF_USERNAME], data[CONF_PASSWORD], websession)
  File "/usr/local/lib/python3.8/site-packages/pymyq/api.py", line 259, in login
    await api.authenticate(username, password, False)
  File "/usr/local/lib/python3.8/site-packages/pymyq/api.py", line 170, in authenticate
    auth_resp = await self.request(
  File "/usr/local/lib/python3.8/site-packages/pymyq/api.py", line 151, in request
    return await self._send_request(
  File "/usr/local/lib/python3.8/site-packages/pymyq/api.py", line 114, in _send_request
    message = f"Error requesting data from {url}: {data.get('description', str(err))}"
UnboundLocalError: local variable 'err' referenced before assignment

I tried manually updating to pymyq==2.0.12 but seeing the same error.

The indentation seems off in: /usr/local/lib/python3.8/site-packages/pymyq/api.py line 114 which I tried fixing and then I saw another error which adds some more info: 2020-12-26 14:36:27 ERROR (MainThread) [pymyq.api] Error requesting data from https://api.myqdevice.com/api/v5/Login: [Errno 104] Connection reset by peer

dseven commented 3 years ago

Looks like that UnboundLocalError was fixed in https://github.com/arraylabs/pymyq/commit/4f2504e7d69a4c085f8c10e89cc488e667155ef9#diff-6e0d351264188252026200e130afc8ffe6a9e78d42b8d3aa4e840b94180a7166 - it really should have been in a separate commit, though - was harder to find than it should have been!

Why you're getting "Connection reset by peer", I'm not sure.

dseven commented 3 years ago

BTW, if you think you updated to 2.0.12 but still saw that UnboundLocalError, you didn't actually update to 2.0.12.

komailo commented 3 years ago
[root@ott-dockerpool-01 home_assistant]# docker exec -ti home_assistant pip3 install pymyq --upgrade
Requirement already up-to-date: pymyq in /usr/local/lib/python3.8/site-packages (2.0.12)
Requirement already satisfied, skipping upgrade: async-timeout in /usr/local/lib/python3.8/site-packages (from pymyq) (3.0.1)
Requirement already satisfied, skipping upgrade: aiodns in /usr/local/lib/python3.8/site-packages (from pymyq) (2.0.0)
Requirement already satisfied, skipping upgrade: aiohttp in /usr/local/lib/python3.8/site-packages (from pymyq) (3.7.1)
Requirement already satisfied, skipping upgrade: pycares>=3.0.0 in /usr/local/lib/python3.8/site-packages (from aiodns->pymyq) (3.1.1)
Requirement already satisfied, skipping upgrade: yarl<2.0,>=1.0 in /usr/local/lib/python3.8/site-packages (from aiohttp->pymyq) (1.4.2)
Requirement already satisfied, skipping upgrade: typing-extensions>=3.6.5 in /usr/local/lib/python3.8/site-packages (from aiohttp->pymyq) (3.7.4.3)
Requirement already satisfied, skipping upgrade: chardet<4.0,>=2.0 in /usr/local/lib/python3.8/site-packages (from aiohttp->pymyq) (3.0.4)
Requirement already satisfied, skipping upgrade: multidict<7.0,>=4.5 in /usr/local/lib/python3.8/site-packages (from aiohttp->pymyq) (5.1.0)
Requirement already satisfied, skipping upgrade: attrs>=17.3.0 in /usr/local/lib/python3.8/site-packages (from aiohttp->pymyq) (19.3.0)
Requirement already satisfied, skipping upgrade: cffi>=1.5.0 in /usr/local/lib/python3.8/site-packages (from pycares>=3.0.0->aiodns->pymyq) (1.14.4)
Requirement already satisfied, skipping upgrade: idna>=2.0 in /usr/local/lib/python3.8/site-packages (from yarl<2.0,>=1.0->aiohttp->pymyq) (2.10)
Requirement already satisfied, skipping upgrade: pycparser in /usr/local/lib/python3.8/site-packages (from cffi>=1.5.0->pycares>=3.0.0->aiodns->pymyq) (2.20)
WARNING: You are using pip version 20.2.4; however, version 20.3.3 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

It seems the version is up to date inside the container and still seeing the error. It might be that something is not picking up the correct version.

The upgrade command above seems to suggest its updating the path that is being used by Home Assistant.

Let me raise a issue with Home Assistant to get them to update the library.

dseven commented 3 years ago

Already done by https://github.com/home-assistant/core/pull/44328

komailo commented 3 years ago

Yup just saw that and verified that the dev version of Home Assistant has 2.0.12 and MyQ is also working perfectly.

So for others, just run the dev version till home-assistant/core#44328 makes it to a stable release.

komailo commented 3 years ago

Thanks @dseven