首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >curl将请求发送到Ecobee的API,失败的原因是“由于通信错误导致更新失败”。

curl将请求发送到Ecobee的API,失败的原因是“由于通信错误导致更新失败”。
EN

Stack Overflow用户
提问于 2022-02-17 17:05:01
回答 2查看 57关注 0票数 0

因此,我在调温器上的检索信息运行良好,现在我正在尝试更新ecobee上的设置,并且正在接收:

代码语言:javascript
复制
status.code=3
status.message="Update failed due to a communication error."

我的query_string看起来像:

代码语言:javascript
复制
{"selection":{"selectionType":"thermostats","selectionMatch":123456789,"thermostat":{"settings":{"humidity":45}}}}

我的卷发如下:

代码语言:javascript
复制
-X POST https://api.ecobee.com/1/thermostat?format=json --data %7B%22selection%22%3A%7B%22selectionType%22%3A%22thermostats%22%2C%22selectionMatch%22%3A311081045454%2C%22thermostat%22%3A%7B%22settings%22%3A%7B%22humidity%22%3A45%7D%7D%7D%7D -H Content-Type: application/json;charset=UTF-8 -H Authorization: Bearer MY-ACCESS-TOKEN

--data - Ran the query-string through the jq '@URI' filter也尝试过:--data-urlencode -Without the '@URI' filter (this is the method shown by the Ecobee API Doc

这两种方法都返回“更新失败”

我确实有一个用python编写的关于GitHub的项目的工作代码,但是我使用它作为bash/jq/API学习机会(而且,我不知道python)

他的代码显示了成功更新设置的以下内容:

代码语言:javascript
复制
url:1/thermostat
header:{'Content-Type': 'application/json;charset=UTF-8', 'Authorization': 'Bearer MY-ACCESS-TOKEN'}
parameters:{'format': 'json'}
body:{"thermostat": {"settings": {"humidity": 40}}, "selection": {"selectionType": "thermostats", "selectionMatch": "123456789"}}

{'status': {'code': 0, 'message': ''}}

这似乎符合我的卷发要求

这就是我用来建立我的卷发(应该保持正确的引用):

代码语言:javascript
复制
url_request=(-X POST "https://api.ecobee.com/1/thermostat?format=json")
url_body=(--data "$query_string")
url_header=(-H "Content-Type: application/json;charset=UTF-8"
            -H "Authorization: Bearer $access_token")
url+=("${url_request[@]}" "${url_body[@]}" "${url_header[@]}")

thermostat=$(curl -s "${url[@]}")

有人看到明显的东西了吗?

谢谢

EN

回答 2

Stack Overflow用户

发布于 2022-02-17 17:09:08

对于curl,您需要将每个附加的头作为一个字符串(一个参数)提供。把引号放在他们周围:

代码语言:javascript
复制
-H 'Content-Type: application/json;charset=UTF-8'
-H 'Authorization: Bearer MY-ACCESS-TOKEN'
票数 0
EN

Stack Overflow用户

发布于 2022-02-19 00:36:36

将此归因于用户错误!

@pmr.很抱歉把你的时间浪费在这上面。我的json查询字符串已关闭。确实是

代码语言:javascript
复制
{"selection":{"selectionType":"thermostats","selectionMatch":123456789,"thermostat":{"settings":{"humidity":45}}}}

而且应该是:

代码语言:javascript
复制
{"selection":{"selectionType":"thermostats","selectionMatch":123456789},"thermostat":{"settings":{"humidity":45}}}

“恒温器”应该在顶层,而不是在“选择”之下。

我不想说我花了多少时间看这个直到我注意到

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71162423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档