Govee API 响应错误代码 400

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

我试图通过 Python 中的 Govee API 更改我的 Govee 灯的颜色,但状态代码返回 400。我查阅了 Govee-API-Documentation,但这就是我能想到的:

headers = {
    "Content-Type": "application/json",
    "Govee-API-Key": self.govee_key2
}

body = {
    "device": self.pc_light_mac,
    "model": "H6003",
    "cmd": {
        "name": "color", 
        "value": {
            "r": 255, 
            "g": 255, 
            "b": 255
        }
    }
}

r = requests.put("https://developer-api.govee.com/v1/devices/control", headers=headers, params=body)
print(r.status_code)

我重新检查了Govee应用程序中的mac地址,但仍然... 我试着换另一个灯,同样的问题 我试过其他cmd,还是400

谢谢

python api python-requests http-status-code-400
1个回答
0
投票
import requests    
url = f'https://developer-api.govee.com/v1/devices/control'    
headers = {
    'Govee-API-Key': api_key,
    'Content-Type': 'application/json'
}    

content = {
    'device': device_id,
    'model': 'H6061',
    'cmd': {
        'name': 'turn',
        'value': 'on'
    }
}

response = requests.put(url, headers=headers, json=content)

这是我为同样的任务而工作的代码——你在“json”关键字下传递多汁的部分。

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