tuya / tuya-iot-python-sdk

Tuya IoT Python SDK for Tuya Open API.
MIT License
130 stars 49 forks source link

Error code "1010" causing a "token invalid" #76

Closed abdullah20401 closed 1 year ago

abdullah20401 commented 1 year ago

Hi, I am getting an error {'code': 1010, 'msg': 'token invalid', 'success': False, 't': 1682574088236, 'tid': '27e13586e4be11eda0c0360158882c1b'}.

Here is my code

from tuya_iot import TuyaOpenAPI
import json

secrets = json.load(open('secret.json', 'r'))

ACCESS_ID = secrets['access_id']
ACCESS_KEY = secrets['access_key']

ENDPOINT = secrets['endpoint']

USERNAME = secrets['username']
PASSWORD = secrets['password']

LIGHTBULB_DEVICE_ID = secrets['lightbulb_device_id']

openapi = TuyaOpenAPI(ENDPOINT, ACCESS_ID, ACCESS_KEY)
openapi.connect(USERNAME, PASSWORD)

commands = {
    'commands': [
        {
            'code': 'switch_led',
            'value': True
        }
    ]
}

result = openapi.post(
    f'/v1.0/iot-03/devices/{LIGHTBULB_DEVICE_ID}/commands', commands)
print(result)

Thank You,

abdullah20401 commented 1 year ago

It looks like I resolved it by using tuya-connector-python instead.

Here is how my code looks like now:

from tuya_connector import TuyaOpenAPI
import json

secrets = json.load(open('secret.json', 'r'))

ACCESS_ID = secrets['access_id']
ACCESS_KEY = secrets['access_key']

ENDPOINT = secrets['endpoint']

USERNAME = secrets['username']
PASSWORD = secrets['password']

LIGHTBULB_DEVICE_ID = secrets['lightbulb_device_id']

openapi = TuyaOpenAPI(ENDPOINT, ACCESS_ID, ACCESS_KEY)
openapi.connect()

commands = {
    'commands': [
        {
            'code': 'switch_led',
            'value': True
        }
    ]
}

result = openapi.post(
    f'/v1.0/iot-03/devices/{LIGHTBULB_DEVICE_ID}/commands', commands)
print(result)