1

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

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 错误。

也试过邮递员。以下是屏幕截图,如下所示: GET请求成功

POST 请求给出 404

尝试更新 lmtech_thing 中的属性(湿度)值

4

1 回答 1

1

以下代码对我有用:-)

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
于 2018-04-13T09:41:46.547 回答