I have searched and tested for 9 hours now, and i cannot figure out how to make a (seemly simple) JSON POST (not a http url request/get) using Domoticz json.htm url.
I do NOT preffer sending/updating data for bussiness customers over a URL request (GET), like this:
Code: Select all
http://192.168.1.1:8080/json.htm?type=command¶m=udevice&idx=1&nvalue=15
Now....all i get back is ERR, in the wiki is stated a pass is needed, so setting domoticz config:
name "jan"
pass "1234"
Basic-Auth
But nevertheless i cannot get it to work....maybe i am overlooking something....any ideas?
TESTSCRIPT
-----------------------------------------------------------------------------------------------------------
#!/usr/bin/python
import subprocess
import time
import os
import urllib2, urllib
import base64
import requests
import json
from requests.auth import HTTPBasicAuth
serverIP = "192.168.1.1:8080"
#serverIP = "localhost:8080"
deviceId = 1
base64string = base64.b64encode('%s:%s' % ("jan", "1234"))
#currentTemp = subprocess.check_output(["/opt/vc/bin/vcgencmd","measure_temp"])
#currentTemp = float(currentTemp.split("=")[1][:-3])
payload = {'type': 'command', 'param': 'udevice', 'idx': '1', 'nvalue': '0', 'svalue': '55'}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
headers64 = {'Content-type': 'application/json', 'Accept': 'text/plain', 'Authorization': 'Basic %s' % base64string}
print 'Authorization: Basic %s' % base64string
r = requests.post("http://" + serverIP + "/json.htm",data={'type':'command', 'param':'udevice', 'idx':1, 'nvalue':0, 'svalue':55}, headers=headers)
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", data=payload, headers=headers)
print r.status_code, r.reason
print r.text
r = requests.post("http://192.168.1.1:8080/json.htm", "amFuOkpBTg==", json={'type': 'command', 'param': 'udevice', 'idx': '1', 'nvalue': '0', 'svalue': '55'}, headers=headers)
print r.status_code, r.reason
print r.text
r = requests.post("http://192.168.2.12:8080/json.htm", json={'type': 'command', 'param': 'udevice', 'idx': '1', 'nvalue': '0', 'svalue': '55'}, headers={"Authorization": "Basic amFuOkpBTg=="})
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", auth=HTTPBasicAuth('jan', '1234'), data=json.dumps(payload), headers=headers)
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", auth=HTTPBasicAuth('jan', '1234'), data=json.dumps(payload))
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", auth=HTTPBasicAuth('jan', '1234'), data=payload, headers=headers)
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", auth=HTTPBasicAuth('jan', '1234'), data=payload)
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", auth=HTTPBasicAuth('jan', '1234'), json=payload)
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", auth=HTTPBasicAuth('jan', '1234'), json=json.dumps(payload))
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", auth=HTTPBasicAuth('jan', '1234'), json=payload, headers=headers)
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", json=payload, headers=headers64)
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", data=payload, headers=headers64)
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", json=json.dumps(payload), headers=headers64)
print r.status_code, r.reason
print r.text
r = requests.post("http://" + serverIP + "/json.htm", data=json.dumps(payload), headers=headers64)
print r.status_code, r.reason
print r.text
-----------------------------------------------------------------------------------------------------------
RESULT
Authorization: Basic amFuOkpBTg==
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}
200 OK
{
"status" : "ERR"
}