requests.exceptions.HTTPError: 400 Client Error: Bad Request
Closed this issue · 1 comments
My code is this:
import os
import sys
Enable debug logging
import logging
logging.basicConfig(level=logging.DEBUG)
import json
import wyze_sdk
from wyze_sdk import Client
wyze_sdk.set_stream_logger('wyze_sdk', level=logging.DEBUG)
#load_dotenv()
email = '@.com'
pw = '*****'
KeyId = '----'
ApiKey = '************************************************.....'
response = Client().login(
email='gkaragatchliev@hotmail.com',
password=pw,
key_id=KeyId,
api_key=ApiKey
)
I get this error after all DEBUG:
wyze> python .\wyze.py
2024-01-07 12:42:38,297 [DEBUG] wyze_sdk.api.client: access token not provided, attempting to login as @.com
DEBUG:wyze_sdk.api.client:access token not provided, attempting to login as @.com
2024-01-07 12:42:38,297 [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-07 12:42:38,299 [DEBUG] wyze_sdk.service.base: unmodified prepared request
DEBUG:wyze_sdk.service.base:unmodified prepared request
2024-01-07 12:42:38,299 [DEBUG] wyze_sdk.service.base: <PreparedRequest [POST]>
DEBUG:wyze_sdk.service.base:<PreparedRequest [POST]>
2024-01-07 12:42:38,299 [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-07 12:42:38,299 [DEBUG] wyze_sdk.service.base: headers: {'user-agent': 'wyze-sdk-2.0.0', 'Accept-Encoding': 'gzip', 'Accept': '/', 'Connection': 'keep-alive', 'keyid': ', 'apikey': '', 'x-api-key': '', 'appid': '9319141212m2ik', 'appinfo': 'wyze_android_2.19.14', 'phoneid': '526ff40a-91e0-47bf-8918-f3c2c66834f6', 'requestid': '96421709a5ee91f27bca392cdb08d8db', 'signature2': '386e8c25adb64fa926a7737a783fde82', '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': '', 'apikey': '', 'x-api-key': 'RckMFKbsds5p6QY3COEXc2ABwNTYY0q18ziEiSEm', 'appid': '9319141212m2ik', 'appinfo': 'wyze_android_2.19.14', 'phoneid': '526ff40a-91e0-47bf-8918-f3c2c66834f6', 'requestid': '96421709a5ee91f27bca392cdb08d8db', 'signature2': '386e8c25adb64fa926a7737a783fde82', 'Content-Length': '108', 'Content-Type': 'application/json'}
2024-01-07 12:42:38,299 [DEBUG] wyze_sdk.service.base: body: b'{"nonce":"1704660158298","email":"@.com","password":""}'
DEBUG:wyze_sdk.service.base:body: b'{"nonce":"1704660158298","email":"@.com","password":"*********"}'
2024-01-07 12:42:38,299 [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 20, 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
That looks exactly like mine, except I see DEBUG:urllib3.connectionpool:https://auth-prod.api.wyze.com:443 "POST /api/user/login HTTP/1.1" 200 None
instead of the 400
error you're getting. If I put in a knowingly bad password, I see the same error response you pasted above.
Can you please check/try two things:
- if your password has any special characters, please make sure they are properly escaped according to python's string escaping
- regenerate the API key on the wyze site or confirm that the one that was generated for you doesn't have characters like
|
or\
- these also throw off string escaping