【问题标题】:Unable to PUT to Nest无法放置到嵌套
【发布时间】:2014-10-28 15:01:34
【问题描述】:

我无法将像 ambient_temperature_f 这样的 Nest 数据放到 https://developer-api.nest.com 或重定向的 Firebase URL。我怀疑 Nest 有一些特定的东西需要在我正在使用的 Firebase 模块中进行调整 (https://ozgur.github.io/python-firebase/)。

来自firebase.py

@http_connection(60)
def make_put_request(url, data, params, headers, connection):
    """
    Helper function that makes an HTTP PUT request to the given firebase
    endpoint. Timeout is 60 seconds.
    `url`: The full URL of the firebase endpoint (DSN appended.)
    `data`: JSON serializable dict that will be stored in the remote storage.
    `params`: Python dict that is appended to the URL like a querystring.
    `headers`: Python dict. HTTP request headers.
    `connection`: Predefined HTTP connection instance. If not given, it
    is supplied by the `decorators.http_connection` function.

    The returning value is a Python dict deserialized by the JSON decoder. However,
    if the status code is not 2x or 403, an requests.HTTPError is raised.

    connection = connection_pool.get_available_connection()
    response = make_put_request('http://firebase.localhost/users',
                                '{"1": "Ozgur Vatansever"}',
                                {'X_FIREBASE_SOMETHING': 'Hi'}, connection)
    response => {'1': 'Ozgur Vatansever'} or {'error': 'Permission denied.'}
    """
    timeout = getattr(connection, 'timeout')
    response = connection.put(url, data=data, params=params, headers=headers, timeout=timeout)

    print('[make_put_request]: [%s][%s][%s][%s]\n' %(url, data, params, headers))

    if response.ok or response.status_code == 403:
        return response.json() if response.content else None
    else:
        response.raise_for_status()

打印出来:

[make_put_request]: [https://developer-api.nest.com/devices/thermostats/DEVICE_ID/ambient_temperature_f.json?auth=VALID_AUTH_TOKEN][71][{}][{}]

返回错误:

Traceback (most recent call last):
  File "C:\py\nest_auth.py", line 90, in <module>
    put_result = firebase.put(data_url, field_name, 71)
  File "C:\Python34\lib\site-packages\firebase\decorators.py", line 19, in wrapped
    return f(*args, **kwargs)
  File "C:\Python34\lib\site-packages\firebase\firebase.py", line 312, in put
    connection=connection)
  File "C:\Python34\lib\site-packages\firebase\decorators.py", line 19, in wrapped
    return f(*args, **kwargs)
  File "C:\Python34\lib\site-packages\firebase\firebase.py", line 77, in make_put_request
    response.raise_for_status()
  File "C:\Python34\lib\site-packages\requests\models.py", line 808, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request

这在使用 firebaseio.com 目标时有效,但不适用于 Nest:

put_result = firebase.put('/devices/thermostats/DEVICE_ID/', 'ambient_temperature', 71)

【问题讨论】:

    标签: python firebase nest-api


    【解决方案1】:

    根据documentation ambient_temperature_f 是一个只读字段,表示恒温器报告的环境温度。覆盖它是没有意义的,因为它是传感器读数。

    我想你想写信给target_temperature_f,这是恒温器应该加热或冷却到的温度。

    【讨论】:

    • 我最近确实注意到了这一点,但不幸的是我仍然遇到同样的错误。使用 Nest 的 Chrome 开发人员工具,我实际上可以更改显示为报告温度的值。一段时间后,Nest 将其设置回实际的恒温器值。
    • 有没有办法将所需的值附加到 url,就像 access_token 一样?例如,附加 ?value=71 之类的东西。
    • 不,REST API 只接受 JSON 负载,不接受查询参数,而且 Firebase API 只使用 Firebase 语法。
    猜你喜欢
    • 2016-09-24
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    • 1970-01-01
    相关资源
    最近更新 更多