gboudreau / nest-api

Unofficial Nest Learning Thermostat API
GNU Lesser General Public License v3.0
300 stars 93 forks source link

406 Not Acceptable #98

Closed joe248 closed 4 years ago

joe248 commented 4 years ago

I've been using this class for a while to do some automation with my Nest. Sometime within the past day it stopped working. When trying to log in I get:

PHP Fatal error:  Uncaught RuntimeException: Error: Response from request to https://home.nest.com/user/login is not valid JSON data. Response: <html><head><title>406 Not Acceptable</title></head><body bgcolor="white"><center><h1>406 Not Acceptable</h1></center><hr><center>nginx</center></body></html> in /home/homeassistant/custom/includes/nest.class.php:1276
Stack trace:
#0 /home/homeassistant/custom/includes/nest.class.php(1178): Nest->doRequest('POST', 'https://home.ne...', Array, true, Array)
#1 /home/homeassistant/custom/includes/nest.class.php(1106): Nest->doPOST('https://home.ne...', Array)
#2 /home/homeassistant/custom/includes/nest.class.php(136): Nest->login()
#3 /home/homeassistant/custom/scripts/update_nest_target_humidity.php(13): Nest->__construct()
#4 {main}
  thrown in /home/homeassistant/custom/includes/nest.class.php on line 1276

Anyone else getting this error?

bauzer714 commented 4 years ago

Same for me - it looks like they deployed some changes. Can you confirm if you're a converted Google account or using Nest login?

joe248 commented 4 years ago

No, I have not converted to a Google account

bauzer714 commented 4 years ago

It appears that the endpoint has changed and reCAPTCHA has been implemented. I'm curious if the Google accounts are also having errors.

image

joe248 commented 4 years ago

What client does this library emulate? The iOS app?

bauzer714 commented 4 years ago

Web browser

joe248 commented 4 years ago

I see the browser user agent in the login method but what is this then?

gboudreau commented 4 years ago

The line you mention in the login method is used for Google accounts only. The Nest/2.1.3 CFNetwork/548.0.4 user-agent is used for Nest accounts, which was used in an old version of the mobile app. Maybe the mobile app login endpoint or content changed.

For Nest accounts, we send a POST to https://home.nest.com/user/login, not https://home.nest.com/session. If that last endpoint is used on the web, and requires a recaptcha, we can't use it. If someone that still has a Nest account can trace what the iOS or Android app does, to login, and compare with https://github.com/gboudreau/nest-api/blob/8ab160f0c2a37ac480fb9c7ee32f7ceab110eb2a/nest.class.php#L1106, that might shed some light on what is happening.

Of note: Google Accounts are still working as expected, at least for me that set it up a few weeks ago.

thecodingfrog commented 4 years ago

same here with the 406 error

doctorkb commented 4 years ago

For Nest accounts, we send a POST to https://home.nest.com/user/login, not https://home.nest.com/session. If that last endpoint is used on the web, and requires a recaptcha, we can't use it. If someone that still has a Nest account can trace what the iOS or Android app does, to login, and compare with

I'm happy to attempt this trace, but I have no idea on how to snoop on these connections via iOS.

I would like to migrate, but I have other integrations that aren't ready for WWGA yet...

brendandebeasi commented 4 years ago

They use certificate pinning on iOS, so I was unable to snoop the connection. That said it looks like the login page makes reference to Recaptcha, so I would assume that is locked down too now :(

stuartajc commented 4 years ago

I'm seeing the 406 error too, with a Nest account (not Google). Since I'm logging responses, I know that this error started between 1900-1910 UTC/GMT on 11 Nov 2019

bauzer714 commented 4 years ago

All "Nest" account users are impacted. I noticed the Android app login references reCAPTCHA too. I'm guessing that any "Nest logins" in the short term future will require reCAPTCHA and any "fix" would be short lived. I'd be happy to try to look into this further, but I merged with Google login to restore my services.

joe248 commented 4 years ago

Did you have any issues or lost functionality after moving to the Google login?

doctorkb commented 4 years ago

Did you have any issues or lost functionality after moving to the Google login?

There is one big thing preventing me from switching today: I use my Nest as the conduit between my Vivint alarm and Hubitat Elevation to determine the home/away status by whether my alarm is armed or not... and those links will both break when I convert the Nest to a Google account.

I'd happily try faking the Nest login by copying a cookie from a successful web login...

joe248 commented 4 years ago

I was able to get it working again by setting the USER_AGENT to 'Nest/5.0.0.23 (iOScom.nestlabs.jasper.release) os=11.0' and LOGIN_URL to 'https://home.nest.com/session'

Let me know if that works for you guys.

a-b-s commented 4 years ago

I was able to get it working again by setting the USER_AGENT to 'Nest/5.0.0.23 (iOScom.nestlabs.jasper.release) os=11.0' and LOGIN_URL to 'https://home.nest.com/session'

Let me know if that works for you guys.

Changing the parameters in the nest.class.php file to the suggested user agent and login url, restored functionality!

vdleun commented 4 years ago

Let me know if that works for you guys.

To confirm: this change also works for me. Thank you!

thecodingfrog commented 4 years ago

I was able to get it working again by setting the USER_AGENT to 'Nest/5.0.0.23 (iOScom.nestlabs.jasper.release) os=11.0' and LOGIN_URL to 'https://home.nest.com/session'

Let me know if that works for you guys.

Yep that works, you're the man!

gboudreau commented 4 years ago

Super, thanks @joe248.

doctorkb commented 4 years ago

I was able to get it working again by setting the USER_AGENT to 'Nest/5.0.0.23 (iOScom.nestlabs.jasper.release) os=11.0' and LOGIN_URL to 'https://home.nest.com/session'

Let me know if that works for you guys.

Works here, too. Thank you SO much!

stuartajc commented 4 years ago

I was able to get it working again by setting the USER_AGENT to 'Nest/5.0.0.23 (iOScom.nestlabs.jasper.release) os=11.0' and LOGIN_URL to 'https://home.nest.com/session'

Let me know if that works for you guys.

Brilliant, works great. Thanks