shauntarves/wyze-sdk

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://auth-prod.api.wyze.com/api/user/login

Closed this issue · 13 comments

My code is
import os
import sys
import logging
logging.basicConfig(level=logging.DEBUG)
import json
from wyze_sdk import Client
response = Client().login(email=email, password=pw,
key_id=KeyId,
api_key=ApiKey)

Where I've created and assigned the above variables.

When I try to log on to the API I get the above error.
The website really says: "This page isn’t working right now"

Is that expected?

THe stack is like:

File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\service\base.py", line 132, in do_post
return self._do_request(client, req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\service\base.py", line 106, in _do_request
raise err
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\service\base.py", line 93, in _do_request
response.raise_for_status()
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://auth-prod.api.wyze.com/api/user/login

Same issue here.

Hi folks...this login method hasn't been supported for some time now as Wyze changed security models back in July 2023.

Please update your wyze-sdk package and follow the instructions here: https://github.com/shauntarves/wyze-sdk?tab=readme-ov-file#wyze-api-keyid-support

Thanks Shaun,

I tried this already. When running it this way:

response = Client().login(
email=os.environ[email],
password=os.environ[pw],
key_id=os.environ[KeyId],
api_key=os.environ[ApiKey]

I get this error:
email=os.environ[email],
~~~~~~~~~~^^^^^^^
File "", line 679, in getitem
KeyError: 'g....@hotmail.com'

I have verified that the email is correct, I use it to log in to Wyze and generated the Keys.
What could be the reason why the os does not like my email?

It doesn't look like you have your environment variables correctly configured. If you are new to programming or python, skip using the os.environ and just code in the values as strings until you know things are working:

response = Client().login(
email='g...@hotmail.com',
password='<your password>',
key_id='<your key id>',
api_key='<your api key>'

Shaun, this leads us back to the same code and issue as when we started the thread.

File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://auth-prod.api.wyze.com/api/user/login
PS C:\Users\gkara\OneDrive\Desktop\Computer_Science\CS50p\wyze>

I would say let's start with checking the version of the library that you have - I've confirmed that login is working just fine for myself and others.

pip info will give you this data.

I have the package installed, but when I call this command, I get:

pip info
ERROR: unknown command "info"

Then I try
wyze> pip install wyze-sdk
Requirement already satisfied: wyze-sdk in c:\users\gkara\appdata\local\programs\python\python311\lib\site-packages (2.0.0)
Requirement already satisfied: requests in c:\users\gkara\appdata\local\programs\python\python311\lib\site-packages (from wyze-sdk) (2.31.0)
...

Gah, sorry, I meant pip list - anyway, it looks like you have 2.0.0 installed, which is the latest.

Can you confirm your key_id value is a 32-character long string with 5 dash-separated segments and your api_key value is a longer string - maybe 50ish characters uppercase and lowercase, with numbers?

I can confirm.

image

Okay, let's try bumping the log level:

wyze_sdk.set_stream_logger('wyze_sdk', level=logging.DEBUG)

if you can paste the content of that (sanitize any unhashed sensitive values)

import os
import sys
import logging
logging.basicConfig(level=logging.DEBUG)
import json
from wyze_sdk import Client

wyze_sdk.set_stream_logger('wyze_sdk', level=logging.DEBUG)

"wyze_sdk" is not defined

You have to import wyze_sdk first - this is just normal python usage at this point

wyze> python .\wyze.py
2024-01-06 15:58:20,547 [DEBUG] wyze_sdk.api.client: access token not provided, attempting to login as g__@,,,.com
DEBUG:wyze_sdk.api.client:access token not provided, attempting to login as g...@....com
2024-01-06 15:58:20,547 [DEBUG] wyze_sdk.service.base: merging request-specific headers into session headers
DEBUG:wyze_sdk.service.base:merging request-specific headers into session headers
2024-01-06 15:58:20,553 [DEBUG] wyze_sdk.service.base: unmodified prepared request
DEBUG:wyze_sdk.service.base:unmodified prepared request
2024-01-06 15:58:20,553 [DEBUG] wyze_sdk.service.base: <PreparedRequest [POST]>
DEBUG:wyze_sdk.service.base:<PreparedRequest [POST]>
2024-01-06 15:58:20,553 [INFO] wyze_sdk.service.base: requesting POST to https://auth-prod.api.wyze.com/api/user/login
INFO:wyze_sdk.service.base:requesting POST to https://auth-prod.api.wyze.com/api/user/login
2024-01-06 15:58:20,553 [DEBUG] wyze_sdk.service.base: headers: {'user-agent': 'wyze-sdk-2.0.0', 'Accept-Encoding': 'gzip', 'Accept': '/', 'Connection': 'keep-alive', 'keyid': 'e...................c', 'apikey': '&())(**)))', 'x-api-key': 'RckM.........................8ziEiSEm', 'appid': '9319141212m2ik', 'appinfo': 'wyze_android_2.19.14', 'phoneid': '58....b-2..6-473f-8..6-51......2a', 'requestid': '5c....................bd', 'signature2': '68a................5b3a6', 'Content-Length': '108', 'Content-Type': 'application/json'}
DEBUG:wyze_sdk.service.base:headers: {'user-agent': 'wyze-sdk-2.0.0', 'Accept-Encoding': 'gzip', 'Accept': '
/*', 'Connection': 'keep-alive', 'keyid': 'ed..................4c', 'apikey': 'U4...........................zSE', 'x-api-key': 'R..............ziEiSEm', 'appid': '9319141212m2ik', 'appinfo': 'wyze_android_2.19.14', 'phoneid': '58.......2a', 'requestid': '5c034bd27b376f70b6d252267294bebd', 'signature2': '68af356bcd8c3e747de25bc77cd5b3a6', 'Content-Length': '108', 'Content-Type': 'application/json'}
2024-01-06 15:58:20,554 [DEBUG] wyze_sdk.service.base: body: b'{"nonce":"1704585500547","email":"g......@.........com","password":"5...8..2"}'
DEBUG:wyze_sdk.service.base:body: b'{"nonce":"1704585500547","email":"g.......v@............com","password":"5...........2"}'
2024-01-06 15:58:20,555 [DEBUG] wyze_sdk.service.base: settings: {'proxies': OrderedDict(), 'stream': False, 'verify': True, 'cert': None}
DEBUG:wyze_sdk.service.base:settings: {'proxies': OrderedDict(), 'stream': False, 'verify': True, 'cert': None}
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): auth-prod.api.wyze.com:443
DEBUG:urllib3.connectionpool:https://auth-prod.api.wyze.com:443 "POST /api/user/login HTTP/1.1" 400 None
Traceback (most recent call last):
File "C:\Users\gkara\OneDrive\Desktop\Computer_Science\CS50p\wyze\wyze.py", line 22, in
response = Client().login(
^^^^^^^^^^^^^^^
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\api\client.py", line 184, in login
response = self._auth_client().user_login(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\service\auth_service.py", line 88, in user_login
response = self.api_call(
^^^^^^^^^^^^^^
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\service\auth_service.py", line 58, in api_call
return super().api_call(
^^^^^^^^^^^^^^^^^
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\service\base.py", line 347, in api_call
return super().api_call(
^^^^^^^^^^^^^^^^^
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\service\base.py", line 204, in api_call
return self.do_post(url=api_url, headers=headers, payload=json, params=params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\service\base.py", line 132, in do_post
return self._do_request(client, req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\service\base.py", line 106, in _do_request
raise err
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\wyze_sdk\service\base.py", line 93, in _do_request
response.raise_for_status()
File "C:\Users\gkara\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://auth-prod.api.wyze.com/api/user/login