首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法用api将数据上传到thingworx上

无法用api将数据上传到thingworx上
EN

Stack Overflow用户
提问于 2018-04-10 11:32:26
回答 1查看 950关注 0票数 1

尝试了许多方式上传数据(邮递员,httpie等给他们的网站)在thingworx上,但无法做到这一点。请查看以下代码以上载thingworx上的数据:

代码语言:javascript
复制
import requests
import json
app_key = 'xxxx'
url = 'http://pp-1804040542ze.devportal.ptc.io/Thingworx/Things/lmtech_thing/Properties/humidity'
prms = {'appKey': app_key}
hdrs = {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
}
data = {'humidiy': '20'}
text = json.dumps(data)
print 'data: ' + text
r = requests.put(url, params=prms, headers=hdrs, data=text)
print r.status_code

成功地创建了东西和密钥。但是它总是返回404错误。

也和邮递员一起尝试过。下面是截图:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-13 09:41:46

以下代码适用于我:)

代码语言:javascript
复制
import requests  # Import requests library to send requests to Thingworx

url = 'http://52.199.28.120:8080/Thingworx/Things/work_thing/Properties/temp'
# temp is one of my property name
value = 12    # Upload 12 on Thingworx

headers = {
    'Content-Type': 'application/json',
    'appkey': 'xxxxxxxxxxxxxxxxxxxxxx',
    'Accept': 'application/json',
    'x-thingworx-session': 'true',
    'Cache-Control': 'no-cache',
}

data = {"temp": value}   # JSON data to upload on Thingworx

response = requests.put(url, headers=headers, json=data)
# Note that we have to send put request

print 'Response Code:', response.status_code
# If 200 then data has been uploaded successfully
print 'Response Content:', response.content
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49752560

复制
相关文章

相似问题

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