【问题标题】:Govee API responses with the error code 400Govee API 响应错误代码 400
【发布时间】:2023-02-21 07:31:43
【问题描述】:

我试图通过 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 地址,但仍然... 我试着换另一个灯,同样的问题 我尝试了其他命令,仍然是 400

谢谢

【问题讨论】:

    标签: python api python-requests http-status-code-400


    【解决方案1】:
    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”关键字下传递了多汁的部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      相关资源
      最近更新 更多