gpt4 book ai didi

python - 无法使用 api 将数据上传到 thingworx

转载 作者:可可西里 更新时间:2023-11-01 17:24:09 30 4
gpt4 key购买 nike

尝试了很多方法在 thingworx 上上传数据(他们网站上给出的 postman 、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

已成功创建事物和 key 。但它总是返回 404 错误。

也尝试过 postman 。以下是屏幕截图,如下所示: GET request is successful

POST request is giving 404

Trying to update the property (humidity) value in lmtech_thing

最佳答案

以下代码对我有用:-)

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

关于python - 无法使用 api 将数据上传到 thingworx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49752560/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com