core: MyQ Integration Receiving 403 Forbidden After Upgrading to 2023.9.X
The problem
MyQ Integration stopped working after upgrading to 2023.9.X. Manually verified that credentials indeed work on same Wifi network. Prior to the upgrade, everything was working fine with no issues.
2023-09-26 15:31:11.077 DEBUG (MainThread) [pymyq.request] Sending myq api request https://accounts.myq-cloud.com/api/v6.0/accounts and headers {‘Authorization’: 'Bearer RandomRandomRandom} with connection pooling 2023-09-26 15:31:11.099 DEBUG (MainThread) [pymyq.request] Attempt 5 request failed with exception : 403 - Forbidden 2023-09-26 15:31:11.099 DEBUG (MainThread) [pymyq.api] Error requesting data from https://accounts.myq-cloud.com/api/v6.0/accounts: 403 - Forbidden
What version of Home Assistant Core has the issue?
core-2023.9.3
What was the last working version of Home Assistant Core?
core-2023.8.6
What type of installation are you running?
Home Assistant OS
Integration causing the issue
MyQ
Link to integration documentation on our website
https://www.home-assistant.io/integrations/myq/
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
Logger: homeassistant.config_entries
Source: config_entries.py:1248
First occurred: 3:21:47 PM (1 occurrences)
Last logged: 3:21:47 PM
Config entry 'xxxxxx@xxxxxx.com' for myq integration not ready yet: Error requesting data from https://accounts.myq-cloud.com/api/v6.0/accounts: 403 - Forbidden; Retrying in background
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Reactions: 16
- Comments: 202 (22 by maintainers)
This is the complete snippet that worked for me - Starting at the line below
last_error = ""
on Line 117 Ending beforeif attempt != 0:
request.py.txt
Probably because we all like to help each other and nothing is really happening to resolve the problem… other than find another way …
This is not a discussion forum. People posting workarounds that are easily Googleable over and over and ranting to the point where the entire purpose of a GitHub issue, to discuss how to solve the issue properly, is near impossible. This is the exact reason why the last issue’s discussion was locked. There are official discussion forums where this talk won’t actively disrupt resolving the issue. Every time you post a message just to call someone petty for trying to keep the discussion focused you are sending an email to all the developers and hindering progress on this.
Edit: imo posting a workaround is fine because it also might give the developers a clue where to look for a solution by seeing something that is working so far. But tech supporting that such as how to set up the alternative packages or how to edit a file in Linux is where it derails due to constant unrelated messages clogging up the hunt for the solution, that’s where discussion should pivot to the forums.
The temporary fix no longer works for me. Has been working for a week but now, no matter what string I put it still says unavailable.
The issue is that the plugin uses the HA helper aiohttp client, which includes a HA user agent. I am guessing they are just blocking any HA user agent.
https://github.com/home-assistant/core/blob/9261ad14e26ca0907681d5e8bd3a4f362fafb62f/homeassistant/helpers/aiohttp_client.py#L148
I modified pymyq to remove user-agent from request where Authorization header is present and it is working again.
Added these lines around the line below, will defer other who knows the HA helper code to determine what the proper fix is.
https://github.com/arraylabs/pymyq/blob/master/pymyq/request.py#L118
The workaround that @changyang1230 and I are discussing is not easily Googleable unless you count finding this thread in the Google search results. I spent half the day yesterday doing that and their comment a little while ago was the first instance of clear steps for using HB and HA together. So come off it.
That’s exactly what we’re doing. “Solving the issue properly” is an umbrella that includes circumventing code that is completely broken through alternative means.
Then maybe be a person and say that instead of just behaving like a Redditor by spamming thumbs downs at people who are trying to fix and help others fix their problems. If you actually care, it shouldn’t take somebody saying “Hey, why are you just thumbs downing everything?”.
For those using Home Assistant OS here is what worked for me at the time of posting this…
Download the “Advanced SSH & Web Terminal” add-on from Settings -> Addon area. At first I tried this with the “Terminal & SSH” add-on and it did not work, so make sure your using the “Advanced SSH & Web Terminal” addon. When you download the plugin, first go to the config tab and input any password you like, also you must ensure that “unprotected mode” is turned on, hit save and start the addon, then simply copy & paste…
docker exec -it homeassistant sed -i.bak "34s/None/str(\"ha${RANDOM}\")/" /usr/local/lib/python3.11/site-packages/pymyq/request.py
Restart home assistant and MyQ integration is working again!
Fired up a Homebridge container and had it integrated and working in Home Assistant in less than 15 minutes. Working like a champ now.
Hacking at the User-Agent strings is clearly a failed proposition. It’s the same thing that was being done a few years ago the last time this integration became unstable. Since continuing User-Agent manipulation is what is merged in 2023.10, I suggest the integration be marked as broken, or someone take the time to implement another underlying library that handles the interactions with the MyQ backend properly. I’ve moved to homebridge-myq in the meantime.
hey it’s back up online now for me
It was working great with that fix, which I implemented, but as of today, it no longer is working.
Just get rid of MyQ! Use a shelly relay, all fixed and now local!
Agreed. Be petty somewhere else.
Hey everyone - I’ve taken over as code owner and included in the 2023.10 release are two changes:
The user agent will get spawned on 403 errors
The update interval was changed from 15 seconds to 30. Halving the amount of api calls we make
I do not have a MyQ device, so I am slowly making changes as I do not have much of a way to test. The 429 error is interesting - I have some local changes that include if we get a 429, we don’t retry, but if someone could determine how long you need to wait after a 429, that would be helpful.
As well, everytime the api gets data, it also gets all of the accounts - I plan to change that to just get the accounts ~1 hour or so rather than every api call, which will greatly decrease the amount of calls we make there. I just need to dive in a bit more and try to figure out why they were getting the accounts everytime anyways.
Finally, I am still looking for someone who has a myq to be a codeowner on this project. If you have a MyQ device, know python, and would like to give back to the Home Assistant community, please consider it, you will be able to do a lot more than I can!
The error looks different from before, and it’s still broken even after changing the user agent string on line 34. Is anyone else seeing this on Core-2023.9.3?
Authentication failed: Error requesting data from https://partner-identity.myq-cloud.com/Account/LoginWithEmail?returnUrl=/connect/authorize/callback?client_id%3DIOS_CGI_MYQ%26code_challenge%[REDACTED]%26code_challenge_method%3DS256%26redirect_uri%3Dcom.myqops%253A%252F%252Fios%26response_type%3Dcode%26scope%3DMyQ_Residential%2520offline_access: 403 - Forbidden
The user-agent change fixed the issue previously; but MyQ is being more strict with login requests as of about a day ago.
The fix is to edit
api.py
in the integration, go down to the section commented# Perform login to MyQ
and comment out where it is explicitly assigning the cookie to the request headers (that’s not needed, since aiohttp’s ClientSession already retains the cookies so they don’t need to be explicitly passed; and the code extracting and passing them explicitly here is incorrect anyway); and also to add"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
to the headers.I don’t believe this is MyQ explicitly trying to keep Home Assistant out; I believe it’s just their application firewall being more strict about accepting ‘correct’ requests.
(edit to add: this is in addition to passing a browser-like User-Agent in request.py)
Hey I have an idea. Why don’t all of the chatter move to the forum so people will would like to use this or attempt to address it can. 💡
I was not very clear. Homebridge is a solution that makes devices available to Apple HomeKit. HA has a native HomeKit integration available which pulls HK devices into HA. Search for “Homekit” in the list of integrations.
@Lash-L - I’m not sure if this has been reported yet but I am now getting failures even with the original patch that was created. It worked for about 2 days and then stopped working about 16 hours ago.
Are other users that do have the patch installed experiencing the same issue?
Looks like MyQ is phasing out their web app (“Moved to Mobile” message on their website), so that might mean they are restricting the API access to the mobile apps.
See this thread in the bottom. You can also do this manually, or using the sed command provided. I just opened a shell in my docker container, and cd’ed into the location (note, depends on your installation - I have python3.9).
Appears to be an issue with the user agent. I think MyQ service started rejecting requests that have an empty user agent. I have an older install and didn’t have the issue since recent.
https://community.home-assistant.io/t/myq-403-auth-errors-after-2023-9/612205/16
docker exec -it homeassistant sed -i.bak “34s/None/str("ha${RANDOM}")/” /usr/local/lib/python3.11/site-packages/pymyq/request.py
I think MyQ is just mucking around with their entire system right now. I made zero changes to my integration, which stopped working, then started working again.
The reason why I think MyQ was mucking about with the product, in general, is because back when it started having trouble I think my bridge device got a firmware update that lost data…because it lost half of the control over my Genie opener (it could open but close commands failed, in both HA and MyQ app). I had to re-pair the bridge and opener to get them working fully again…THEN the connection between bridge and opener broke AGAIN just today. Same issue; can open but not close. I am about to pair the two up again, but HA is working just fine otherwise.
I suspect they tried to make updates to the API and push out a firmware update to bridges and some openers to accommodate those API updates…and both were spectacular failures, resulting in reversion or updates to both all over again to fix the issues. What annoys me most is that the broken bit with firmware appears to be such that a door could be left open with no way to close it unless you can physically get to an attached or wireless opener. I’ve been using MyQ for years and never had to physically re-pair the bridge and opener until this recent mess.
While I’m sure some clean-up and updating of this integration was warranted, I don’t think there is an actual bug to fix at this point. Any residual issues still being faced by some are likely the result of further clean-up or rollout of whatever firmware/API changes they recently made. They give such little visibility into their firmware and automatic updates, it’s nearly impossible to be sure who has or has not received their latest update yet.
Tried Method:
docker exec -it homeassistant sed -i.bak “34s/None/str("ha${RANDOM}")/” /usr/local/lib/python3.11/site-packages/pymyq/request.py
Issues persist, following for more advice.
Thank you @Lash-L for your efforts!
I was running 2023.9.2 HA just fine with working myq integration. But at ~8pm on 9/28 PST it stopped working and now I get 403 errors. I had already applied the user agent fix that was the solution when it initially broke a few weeks back. That fix is still in place. I updated it to match the latest fixes just in case but since those are just a different way to choose when to provide a user agent, it didn’t help.
I don’t have an iPhone and don’t use Apple’s HomeKit platform at all. My HomeBridge instance is not connected to anything.
Don’t do the integration setup on your iPhone. You need to set it up through HA. Go into the “integrations” menu in HA, choose “add integration”, choose “apple”, “choose HomeKit device”. This will initiate the setup of MyQ device, and you will need to enter the HB code as part of this setup.
Most likely your existing HK integration is linked to a different HK server setup. You need to create a new HK integration (you can have more than one) that is linked to the unique server code displayed in the HB app, then the new integration will pull in myQ devices from the HB app.
Since this issue is very frustrating, I have decided to use ratgdo’s solution (Thank you Paul) but I have a question that I hope someone can answer. I am going to buy the WEMOS D1 ESP8266 and just solder pin headers on myself but I am a bit confused looking at the wiring diagram on the project page. Can anyone tell me exactly which terminal numbers to use for the Obst/GND/Ctrl connections. I will just use a USB brick for power so I do not need to connect the 3.3V.
Thanks all
While we all wait for a permanent fix. This is what I did. Installed portainer add-on in HA. Added home bridge docker in portainer. Added myq pluggin in home bridge. Linked home assistant to home bridge. Now I controll myq via home assistant via home bridge. I can write more detailed later as I am at the store atm.
Stopped working again 30 minutes ago (5:42PM EST)
Mine went out last night, about 10-11 hours ago. I did the other “fix” after upgrading but not the one mentioned before, is it worth doing or does it not work now as well?
I’m not sure why it worked for others, but when I ran the script:
It didn’t work, I assume because that command nests double quotation marks inside other double quotation marks.
It caused the line to contain this which is a syntax error due to lack of quotes:
I ended up just editing the file myself to have:
(that value is completely made up, I figure that since these losers at MyQ appear to be trying to break our stuff, I’d rather make a request that doesn’t look as explicitly like being Home Assistant).
So anyway I would encourage people to instead use this version of the command:
I haven’t tested it, but I think it has a better chance of working. Good luck!
Sidenote to the owner of this integration: Is this the kind of thing that will likely get fixed in the next stable release? Is that going to be 2023.10?
I see your post on HAOS forum, i will wait until 2023.10 – appreciate all your hard work
Will try tonight, thank you so so much. This is amazing community.
Hello - the wget was pulled as I am reworking the problem to fix it in a official core release.
You can replace that link with https://github.com/Python-MyQ/Python-MyQ/archive/refs/heads/master.zip if you would like
I’d recommend that anyone who hasn’t modified their local code - waits until 2023.10
I’ve been seeing a lot of people make the situation worse for themselves. In two days an official release that has been tested by a lot of people will automatically be applied on your machine - if it was me, I’d wait the two days. Or if you can’t wait - just get the beta
Suggest you replace your files with the latest commit from Lash-L in the feature/timeout branch. This will be merged into core next opportunity. It works nicely. At least for now until myQ mucks it up again.
https://github.com/Python-MyQ/Python-MyQ/tree/feature/timeout
On Mon, Oct 2, 2023 at 6:51 PM tanderson1992 @.***> wrote:
– Dan Silver 62 Clements Rd Newton, MA 02458
Mine just randomly started working 2-3 hours ago, without me doing anything… so weird
If you’re getting 429 errors its because you got rate limited when running the broken code, since that code would hit the API repeatedly to attempt to login and burned through your request quota. Wait a few hours and try again.
The fix to clear the user agent worked for me as well.
How frequently do other working 3rd party solutions (like the homebridge one) connect to get update door states? Is 15 seconds more aggressive? Or does this integration request more data every 15 seconds? Anything that might be causing myq to tighten down access due to server loads?
How did you modify the integration files? Did you clone the project and re-install manually after your fix? I’m running HA in a VM and I cannot locate where the integration files.
I can confirm Dailow’s fix works for me, just add the below snippet on line 118 in your requests file https://github.com/arraylabs/pymyq/blob/master/pymyq/request.py#L118
In Homebridge, I had to go to 3-dot-button in the top right, select Homebridge Settings, and then "Reset Homebridge Accessory’.
Once I did that, HB immediate showed up as detected in HA. I suspect I never removed my connection on the Ipad, but this did the trick.
Latest commit to feature/timeout branch is not working for me.
The attempts at resolving user agent, timed requests, etc have not worked. Unless someone is willing to explore leveraging whatever homebridge is doing (sorry I have no expertise in this matter!) it appears that this integration should be marked broken, and removed from core.
Step 4. HA does not detect HomeBridge or the MyQ device when I do this.
These steps do not work for me. The HomeKit Device integration does not detect anything to initiate setup with - Not my HB instance or the MyQ device.
I’ve been trying to figure the HB -> HA connection out too and I am also not getting anywhere with it by trying to follow what’s been said here. When I go to add an integration and search for HomeKit, I am given two options:
So, we really need some more clear and specific steps for doing this.
@cer2225 this is not the place for unrelated question. Ratgdo is what I use as well, it’s a great solution. But this thread should be used only for myq as it gets crazy as is. Ask that question on the forums or ratgdo git repository
I’m on 2023.09.3 and have been having trouble with the myq integration since start of Sept.
For most of the month, the “useragent” fix had been working for me (through a couple upgrades - I just reapplied it manually).
Yesterday that fix stopped working for me. So what has fixed it tonight was to apply the timeout branch mentioned above.
With Advanced SSH Terminal installed It sort of went like this:
Then restart HA. For me there was a delay before the myq integration would load. You can get a sense of how long by looking at System -> System -> Logs and then filtering on “myq” and then click “Load Full Logs”
There may be log entries like
The “until” time is probably UTC - so convert that to your timezone and then wait until after that time and the integration started working again.
Ok. Only getting “403 - Forbidden” in my issues. Sorry can’t help with 529. They are not in my logs
Test this branch please 😃 @Conundrum
https://github.com/Python-MyQ/Python-MyQ/tree/feature/timeout
There should theoretically be a header that describes how long we need to wait for. That should be printed when you get a 429.
Homebridge is constant. I guess it wasn’t clear? Use homebridge to call the myQ cloud API, then pull HB devices into HA through the HomeKit integration. It works.
Looking into to logs, I’m seeing “403 - Forbidden” errors, causing everything to be offline/unavailable. This is why I I like to have things local, and not cloud based 😡
Throughout this continuing saga over the past few weeks (and previous occasions) with the HA integration not playing nicely with MyQ API, the Homebridge myQ plugin has continued to maintain its connection.
Whatever Homebridge is doing differently, their plugin does not seem to be impacted by the same events that have caused issues for HA.
So my solution/workaroun is to use both integrations in parallel: 1) deploy a Homebridge server, 2) add the myQ plugin to Homebridge, 3) integrate Homebridge with HA, so the HB myQ devices are available to HA, 4) adjust HA automations to call both the HB myQ devices, as well as the HA myQ devices. Basically a belt and suspenders approach, in which one integration acts as a failover in the event the other one goes down.