arraylabs / pymyq

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

Authorization fails when called from AWS #185

Open rjcohn opened 1 year ago

rjcohn commented 1 year ago

This is similar to other reported errors, but I now have an issue that is more consistent and easier to reproduce (if you have an AWS account). If you add valid credentials to example.py, it consistently runs successfully locally (e.g. on my Mac). The same code running on an EC2 server in AWS consistently fails -- the initial auth call to https://partner-identity.myq-cloud.com/connect/authorize fails, returning a 403. I ran into this starting a few weeks ago when my MyQ Alexa skill stopped working (the same time other issues were reported here).

eliasisrael commented 12 months ago

The bug is on line 124 of request. py.

the 429 status returns a header named "retry-after". That field specifies the number of seconds the Client must wait before trying again. Instead, the code on line 124 tries to do exponential back-off, but it starts from a very small value.

If you look at the error header, you will see the server is asking for a wait time of 1750 Seconds or more.

See this link:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After

This explains why shutting down the module and waiting seems to fix the problem. And it explains why the problem is intermittent: it is happening on the Oauth auth cycle, which is somewhat infrequent.

The stuff about user agent strings is a red herring.