在python和C ++中创建Thingworx REST API语句

时间:2018-04-10 21:43:16

标签: python rest api thingworx

我正在制作POST REST API语句到thingworx服务器我的源代码,如下所示,图片是我回来的响应。有人可以解释我做错了什么,以及在C / C ++环境中这样做的正确方法是什么?

源代码:

import RPi . GPIO as GPIO
import time
import requests 
import json
from picamera import PICamera

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN)

camera = Picamera()
url = ‘https://academic-educatorsextension.portal.ptc.io’
headers = { ‘Content-Type’: application/json’, appKey’: ‘077c9a51-c690-4d2a-9254-3568cb0ee6bd’}
payload = {‘Detection’: ‘True’}

i=0

while True:

    i+=1
    state = GPIO.input(11)
    if state = == 0:
        print “we’re clear”
        time.sleep(5)
    elif state == 1:
        print “stop Right There!”
        camera.capture(‘/home/pi/PIR/pics/image{0:04d}.jpg’.format(i))
        response = requests.put(url + ‘/Things/Motion sensor_Coldsteel85/*’,headers=headers, json = payload, verify = False)
        time.sleep(5)

Response

1 个答案:

答案 0 :(得分:0)

由于您通过https发送数据,因此您应使用自签名证书签署您的请求。请参阅以下主题,了解如何通过python执行此操作: