涂鸦Python脚本无法连接。错误 501

问题描述 投票:0回答:1

当我尝试使用 tuya_iot 库连接到 tuya api 时,我收到一个没有说明任何内容的一般错误。

我试过这个:

from tuya_iot import TuyaOpenAPI, TUYA_LOGGER
import logging

TUYA_LOGGER.setLevel(logging.DEBUG)

# Cloud project authorization info
ACCESS_ID = 'mysuperID'
ACCESS_KEY = 'mysuperSecretKey'

# For more info, refer to: https://developer.tuya.com/en/docs/iot/api-request?id=Ka4a8uuo1j4t4
ENDPOINT = "https://openapi.tuyaus.com" # Western America Data Center

# Project configuration
USERNAME = '[email protected]'
PASSWORD = 'thePassword of Tuya'

# Initialization of tuya openapi
openapi = TuyaOpenAPI(ENDPOINT, ACCESS_ID, ACCESS_KEY)
openapi.connect(USERNAME, PASSWORD)

我得到了这个:

[2023-11-13 18:44:47,778] [tuya-openapi] Request: method = POST,                 url = https://openapi.tuyaus.com/v1.0/iot-01/associated-users/actions/authorized-login,                params = None,                body = {'username': '[email protected]', 'password': '***', 'country_code': '', 'schema': ''},                t = 1699911887778
[2023-11-13 18:44:48,694] [tuya-openapi] Response: {
  "code": 501,
  "msg": "request fail with unkown error",
  "success": false,
  "t": 1699911889502,
  "tid": "debb0af0826d11ee8088063dea7c5c23"
}

但我希望能够成功连接。

python sdk iot tuya
1个回答
0
投票

安装以下库后我可以解决此问题:

pip3 install tuya-connector-python

我在以下文档的第 3 部分的第一步中找到了这个: https://developer.tuya.com/en/docs/iot/device-control-best-practice-python?id=Kav4zc0nphsn5

之后我只做了:

from tuya_connector import TuyaOpenAPI

# Cloud project authorization info
ACCESS_ID = 'mysuperID'
ACCESS_KEY = 'mysuperSecretKey'

# For more info, refer to: https://developer.tuya.com/en/docs/iot/api-request?id=Ka4a8uuo1j4t4
API_ENDPOINT= 'https://openapi.tuyaus.com' # Western America Data Center
    
# Init OpenAPI and connect
openapi = TuyaOpenAPI(API_ENDPOINT, ACCESS_ID, ACCESS_KEY)
openapi.connect()

效果很好。

© www.soinside.com 2019 - 2024. All rights reserved.