arraylabs / pymyq

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

Possible API Being Updated #53

Closed a-bianucci closed 3 years ago

a-bianucci commented 3 years ago

Doors now showing unavailable.

Others are starting to notice as well.

Error Logs show: 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

Not sure if they are updating the API, or something else.

rickscherer commented 3 years ago

2020-12-16 14:28:39 DEBUG (MainThread) [pymyq.api] Sending authentication request to MyQ 2020-12-16 14:28:39 DEBUG (MainThread) [pymyq.api] Sending myq api request https://api.myqdevice.com/api/v5/Login 2020-12-16 14:28:39 DEBUG (MainThread) [pymyq.api] Attempt 1 request failed with exception: [Errno 104] Connection reset by peer 2020-12-16 14:28:39 WARNING (MainThread) [pymyq.api] Device update failed; trying again in 2 seconds 2020-12-16 14:28:41 DEBUG (MainThread) [pymyq.api] Sending myq api request https://api.myqdevice.com/api/v5/Login 2020-12-16 14:28:41 DEBUG (MainThread) [pymyq.api] Attempt 2 request failed with exception: [Errno 104] Connection reset by peer 2020-12-16 14:28:41 WARNING (MainThread) [pymyq.api] Device update failed; trying again in 4 seconds 2020-12-16 14:28:45 DEBUG (MainThread) [pymyq.api] Sending myq api request https://api.myqdevice.com/api/v5/Login 2020-12-16 14:28:45 DEBUG (MainThread) [pymyq.api] Attempt 3 request failed with exception: [Errno 104] Connection reset by peer 2020-12-16 14:28:45 WARNING (MainThread) [pymyq.api] Device update failed; trying again in 5 seconds 2020-12-16 14:28:50 DEBUG (MainThread) [pymyq.api] Sending myq api request https://api.myqdevice.com/api/v5/Login 2020-12-16 14:28:50 DEBUG (MainThread) [pymyq.api] Attempt 4 request failed with exception: [Errno 104] Connection reset by peer 2020-12-16 14:28:50 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

a-bianucci commented 3 years ago

Rick you thinking it's an updated API then as the URL is actually available or?

rickscherer commented 3 years ago

home-assistant/core#44303

rickscherer commented 3 years ago

Rick you thinking it's an updated API then as the URL is actually available or?

Perhaps an API change? I don't really know as a simple curl for authentication is throwing an error.

a-bianucci commented 3 years ago

That's how I read the logs to... that last line regarding local variable err wasn't sure about. Here is to hoping it just comes right back up.

irctrakz commented 3 years ago

The myq app on ios has a login URL of partner-identity.myq-cloud.com, that appears to be different than the existing /Login URL (api.myqdevice.com)

a-bianucci commented 3 years ago

irctrakz if I can figure out the curl string (not a coder), could try and replace the url with what you have see what happens.

rickscherer commented 3 years ago

irctrakz if I can figure out the curl string (not a coder), could try and replace the url with what you have see what happens.

I'm getting the same error against that URL, I believe it's all the same servers - just different FQDN based on client/application.... looking more like possible API change, or just an issue with their API service.

irctrakz commented 3 years ago

Looks like they may also be certificate pinning.... but tbh, my burp skills are rusty.

rickscherer commented 3 years ago

Looking more to be wider spread API issues, IFTTT <> MyQ isn't working either, and that is a supported connection.

irctrakz commented 3 years ago

Yeah, api.myqdevice.com returns a connection reset (not even a 500 or 302), but partner-identity.myq-cloud.com gives a 400

hstern commented 3 years ago

The server is return status code 401 Unauthorized for https://api.myqdevice.com/api/v5/Login

Response body is:

{'code': '401.102', 'message': 'Unauthorized', 'description': 'The current call is Unauthorized.'}

The API._send_request function was expecting err to remain in scope outside of the try-except block, which it doesn't. I submitted #54 to fix that issue so that the error can be properly reported.

Digging deeper, I was mistaken. The server is only dropping connection when you pass the 'User-Agent': 'okhttp/3.10.0' header, so Chamberlain myst be blocking that user agent.

Changing the user agent to 'pymyq' resolves the issue. My garage door is going crazy now.

rickscherer commented 3 years ago

Confirmed that changing User-Agent resolved the problem.

BigRed8150 commented 3 years ago

i changed the User-Agent and i am still having the same issue

Erikcaldwell commented 3 years ago

I just changed the User-Agent and it resolved the issue. I hope this gets pushed to master and released soon.

a-bianucci commented 3 years ago

How do you do that if you are running HASS Os?

can you put a copy of updated file in custome components?

ehendrix23 commented 3 years ago

Version 2.0.12 just released that includes random generator for user agent similar to what they did in HomeBridge.

untergeek commented 3 years ago

Random is fun, but so is trolling them:

DEFAULT_USER_AGENT = "grow_up_MyQ/1.2.3"
GaryOkie commented 3 years ago

I just now installed pymyq 2.0.12 on Home Assistant OS 2020-12. It did not go well. I had previously manually edited api.py with the hardcoded user agent, and that worked fine.

Is there a logic error in the just-updated api.py?

message = f"Error requesting data from {url}: {data.get('description', str(err))}"
UnboundLocalError: local variable 'err' referenced before assignment

EDIT: I updated the myq manifest (requirements) file to also point to 2.0.12, restarted HA and the error is gone. Changed nothing else. Not sure what really caused the error, but it's gone now. Sorry - Nevermind!

ehendrix23 commented 3 years ago

FYI, with the old manifest it would have downloaded the older version again. So in reality you downgraded back to previous pymy version. With the updated manifest the new 2.0.12 is downloaded and used.

BigRed8150 commented 3 years ago

So i removed the integration and now I cannot get the integration to work, unexpected error when trying to configure. tried pip install pymyq, and i get an error files or directories cannot be found. how do we get the integration back up and running form scratch?

unable to execute 'gcc': No such file or directory error: command 'gcc' failed with exit status 1

ERROR: Failed building wheel for pycares

usedjeans818 commented 3 years ago

Can someone help me understand how the resolution is propagated? I was experiencing this same issue... When I saw that it was "resolved," I was still experiencing the problem. Eventually, I tried deleting the Integration and then reconfiguring it. But, I now get an "Unexpected error" when entering my Username and Password (I've also tried putting them in configuration.yaml). I've checked Supervisor numerous times and no updates are available. Also, I've tried rebooting Home Assistant several times, to no avail.

Here is my log: 2020-12-18 03:20:41 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

Am I doing something wrong? How do I get my Home Assistant to use the new code? I believe this is related to #https://github.com/home-assistant/core/issues/44322

Please help!

a-bianucci commented 3 years ago

Can someone help me understand how the resolution is propagated? I was experiencing this same issue... When I saw that it was "resolved," I was still experiencing the problem. Eventually, I tried deleting the Integration and then reconfiguring it. But, I now get an "Unexpected error" when entering my Username and Password (I've also tried putting them in configuration.yaml). I've checked Supervisor numerous times and no updates are available. Also, I've tried rebooting Home Assistant several times, to no avail.

Here is my log: 2020-12-18 03:20:41 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

Am I doing something wrong? How do I get my Home Assistant to use the new code? I believe this is related to #home-assistant/core#44322

Please help!

usedjeans818,

The resolution hasn't been pushed out through the Hassio \ HASS OS process yet. So you will need to follow the instructions in this link: https://github.com/home-assistant/core/issues/44303.

The reason it's "Closed" is because it's not a HASS\Core issue but was an issue with the PYMYQ Add on. To be honest wasn't an issue with the addon specifically but a change by Chamberlin, that the dev's found a work around for.

usedjeans818 commented 3 years ago

@a-bianucci , thanks for confirming.

However, I am not running Home Assistant in a docker and get the following when I run the command from that webpage:

~ $ docker exec -t -i homeassistant /bin/bash -bash: docker: command not found

I can 'cd' into the /usr/local/lib/ directory, but there is no 'python3.8' directory in there. All there is is:

~ $ cd /usr/local/lib lib $ ls libjemalloc.a libjemalloc.so libjemalloc.so.2 libjemalloc_pic.a pkgconfig

Can you maybe help at this stage so I can get MyQ working again? I appreciate any help you can provide.

yajrendrag commented 3 years ago

@usedjeans818 - take a look at your traceback above - it's reporting the path of the file you need to edit - "/usr/local/lib/python3.8/site-packages/pymyq/api.py". So, if you're not finding pthon3.8 in /usr/local/lib, something seems odd. How did you install homeassistant? if, for example, you used a virtual environment, the path would be different... but it would be odd that the path in the venv would be the same as the system path reported in the traceback (or at least that seems to be the system path on ubuntu). but if it's in a VM or container that path could be the same, you just need to be in said VM or container when looking for the directory. You can try sudo find / -type d -name site-packages. If you find more than 1 site-packages directory, you have to determine which python3.8 directory is active for your homeassistant installation. once you find it, you can apply the fix you found that you referenced above.

usedjeans818 commented 3 years ago

@yajrendrag - I installed it on a Raspberry Pi 4 by following https://www.home-assistant.io/getting-started/. I think that's the issue, that it's not running under a docker. I tried the 'sudo find' command and just a 'find' and received:

~ $ sudo find / -type d -name site-packages -bash: sudo: command not found ~ $ find / -type d -name site-packages ~ $

Any other suggestions?

usedjeans818 commented 3 years ago

I finally got into HASSIO and was able to edit the DEFAULT_USER_AGENT! I'll try to document it in case anyone else runs into my issue.

  1. As stated in bullet-point 1, #https://github.com/home-assistant/core/issues/44303#issuecomment-747447389, you can use the Community Add-On "SSH & Web Terminal" to log into HASSIO. (The Official Add-On "Terminal & SSH" is used to SSH into the OS.)
  2. I had tried this earlier, but kept receiving a "502: Bad Gateway" error. The fix for this is to use a different port other than 22 (I used 2222).
  3. Once I was in HASSIO, I followed the rest of the steps from #https://github.com/home-assistant/core/issues/44303#issuecomment-747447389

And, now, my MyQ is working again! Thank you @a-bianucci and @yajrendrag for taking the time to assist me.

mihir2787 commented 3 years ago

Any idea on how to get this to work, if I am using HA in Proxmox on a NUC?