shauntarves/wyze-sdk

API access via token not working

Closed this issue · 1 comments

I have obtained the access & the refresh token via this method:


response = Client().login(

    email='my_email',
    password='my_password',
    key_id='my_keyid',
    api_key='my_apikey'
)

print(f"access token: {response['access_token']}")
print(f"refresh token: {response['refresh_token']}")

now below code:

import sys
from wyze_sdk import Client
from wyze_sdk.errors import WyzeApiError

# Enable debug logging
import logging

logging.basicConfig(level=logging.DEBUG)

try:
    client = Client(token='access_token',
                    refresh_token='refresh_token)
    api_response = client.api_test()
    list_of_cameras = client.cameras.list()

except WyzeApiError as e:
    # You will get a WyzeApiError if the request failed
    print(f"Got an error: {e}")

is leading into this exception:

DEBUG:wyze_sdk.service.base:merging request-specific headers into session headers
DEBUG:wyze_sdk.service.base:unmodified prepared request
DEBUG:wyze_sdk.service.base:<PreparedRequest [POST]>
INFO:wyze_sdk.service.base:requesting POST to https://api.wyzecam.com/api.test
DEBUG:wyze_sdk.service.base:headers: {'User-Agent': 'okhttp/4.7.2', 'Accept-Encoding': 'gzip', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '1132'}
DEBUG:wyze_sdk.service.base:body: b'{"access_token":"access_token}'
DEBUG:wyze_sdk.service.base:settings: {'proxies': OrderedDict(), 'stream': False, 'verify': True, 'cert': None}
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.wyzecam.com:443
DEBUG:urllib3.connectionpool:https://api.wyzecam.com:443 "POST /api.test HTTP/1.1" 404 681
Traceback (most recent call last):
  File "/home/user/PycharmProjects/WyzeAPI/main.py", line 26, in <module>
    api_response = client.api_test()
  File "/home/user/PycharmProjects/WyzeAPI/.venv/lib/python3.13/site-packages/wyze_sdk/api/client.py", line 273, in api_test
    return self._api_client().api_call(api_method, http_verb=http_verb, json=kwargs)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/PycharmProjects/WyzeAPI/.venv/lib/python3.13/site-packages/wyze_sdk/service/api_service.py", line 66, in api_call
    return super().api_call(api_method, http_verb=http_verb, data=None, params=None, json=json, headers=headers, auth=None)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/PycharmProjects/WyzeAPI/.venv/lib/python3.13/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, method=http_verb)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/PycharmProjects/WyzeAPI/.venv/lib/python3.13/site-packages/wyze_sdk/service/base.py", line 132, in do_post
    return self._do_request(client, req)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/home/user/PycharmProjects/WyzeAPI/.venv/lib/python3.13/site-packages/wyze_sdk/service/base.py", line 106, in _do_request
    raise err
  File "/home/user/PycharmProjects/WyzeAPI/.venv/lib/python3.13/site-packages/wyze_sdk/service/base.py", line 93, in _do_request
    response.raise_for_status()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/user/PycharmProjects/WyzeAPI/.venv/lib/python3.13/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.wyzecam.com/api.test

Hey there @jak83A,

I honestly haven't used that api_test endpoint in a long time. Try just listing devices or something like that and everything should work.