OpenURL HTTP Response Error parsing json to LUA table

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

OpenURL HTTP Response Error parsing json to LUA table

Post by rwblinn »

Hi,

running below dzVents Lua test snippet (openURL) gives error "Error parsing json to LUA table" after finishing.
The openURL works, but the HTTP result isJSON=False!

Looked up the source of ~domoticz\dzVents\runtime\Utils.lua what the cause could be = seemed function fromJSON
Implemented a workaround = adding check on string empty, no error anymore.

Any hints appreciated what the cause could be and how to resolve --- without below workaround.

Code: Select all

function self.fromJSON(json, fallback)
	-- ADDED: Check if a string is empty 
	if _.str(json) == nil or _.str(json) == '' then
		return fallback
	end
...
Domoticz Log

Code: Select all

2021-03-05 18:51:23.045 Status: dzVents: Debug: CCUJACK: OpenURL: url = http://192.168.1.70:2121/device/000A18A9A64DAC/1/SET_POINT_TEMPERATURE/~pv
2021-03-05 18:51:23.045 Status: dzVents: Debug: CCUJACK: OpenURL: method = PUT
2021-03-05 18:51:23.045 Status: dzVents: Debug: CCUJACK: OpenURL: post data = {"v":7}
2021-03-05 18:51:23.045 Status: dzVents: Debug: CCUJACK: OpenURL: headers = nil
2021-03-05 18:51:23.045 Status: dzVents: Debug: CCUJACK: OpenURL: callback = CCUJACK
2021-03-05 18:51:23.045 Status: dzVents: Info: CCUJACK: ------ Finished ccu_jack
2021-03-05 18:51:23.045 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-03-05 18:51:25.371 Status: dzVents: Info: Handling httpResponse-events for: "CCUJACK"
2021-03-05 18:51:25.371 Status: dzVents: Info: CCUJACK: ------ Start internal script: ccu_jack: HTTPResponse: "CCUJACK"
2021-03-05 18:51:25.371 Status: dzVents: Info: CCUJACK: ------ Finished ccu_jack
2021-03-05 18:51:25.371 Error: dzVents: Error: (3.1.5) CCUJACK: Error parsing json to LUA table: (invalid json string)
dzVents

Code: Select all

local IDX_SWITCH = 83
local newData = {v=7}  
return {
	on = { devices = { IDX_SWITCH }, httpResponses = { 'CCUJACK' },	},
        logging = { level = domoticz.LOG_DEBUG, marker = "CCUJACK" },		
	execute = function(domoticz, item)
	        domoticz.utils.dumpTable(item)
		if (item.isDevice) then
			domoticz.openURL({
				url = 'http://CCU-IP:2121/device/000A18A9A64DAC/1/SET_POINT_TEMPERATURE/~pv',
				method = 'PUT',
				callback = 'CCUJACK',
				postData = newData
			})
        	end
        end
}
Dump

Code: Select all

2021-03-05 18:56:42.140 Status: dzVents: > isSystem: false
2021-03-05 18:56:42.141 Status: dzVents: > isXML: false
2021-03-05 18:56:42.141 Status: dzVents: > isJSON: false
2021-03-05 18:56:42.141 Status: dzVents: > isTimer: false
2021-03-05 18:56:42.141 Status: dzVents: > isDevice: false
2021-03-05 18:56:42.141 Status: dzVents: > _contentType: application/json
2021-03-05 18:56:42.141 Status: dzVents: > isHardware: false
2021-03-05 18:56:42.141 Status: dzVents: > headers:
2021-03-05 18:56:42.141 Status: dzVents: > Content-Length: 0
2021-03-05 18:56:42.141 Status: dzVents: > Content-Type: application/json
2021-03-05 18:56:42.141 Status: dzVents: > Date: Fri, 05 Mar 2021 17:56:42 GMT
2021-03-05 18:56:42.141 Status: dzVents: > data:
2021-03-05 18:56:42.141 Status: dzVents: > isScene: false
2021-03-05 18:56:42.141 Status: dzVents: > protocol: HTTP/1.1
2021-03-05 18:56:42.141 Status: dzVents: > ok: true
2021-03-05 18:56:42.141 Status: dzVents: > isCustomEvent: false
2021-03-05 18:56:42.141 Status: dzVents: > callback: CCUJACK
2021-03-05 18:56:42.141 Status: dzVents: > statusCode: 200
2021-03-05 18:56:42.141 Status: dzVents: > isGroup: false
2021-03-05 18:56:42.141 Status: dzVents: > isHTTPResponse: true
2021-03-05 18:56:42.141 Status: dzVents: > dump()
2021-03-05 18:56:42.141 Status: dzVents: > baseType: httpResponse
2021-03-05 18:56:42.141 Status: dzVents: > isSecurity: false
2021-03-05 18:56:42.141 Status: dzVents: > statusText: OK
2021-03-05 18:56:42.141 Status: dzVents: > isShellCommandResponse: false
2021-03-05 18:56:42.141 Status: dzVents: > isVariable: false
2021-03-05 18:56:42.141 Status: dzVents: > trigger: CCUJACK
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: OpenURL HTTP Response Error parsing json to LUA table

Post by waaren »

rwblinn wrote: Friday 05 March 2021 19:13

Code: Select all

2021-03-05 18:56:42.141 Status: dzVents: > Content-Length: 0
2021-03-05 18:56:42.141 Status: dzVents: > Content-Type: application/json
Thx. for reporting.

The error message does not break the execution of the script and- is in fact correct.
The return from the HTTP call states in the header that the content is 'application/json' but it does not send a valid JSON.

If you have influence on what the call returns I suggest that it will return something like
{
"status": "OK"
}

{
"status": "NOK"
}


I will discuss with some of the other dzVents / domoticz developers if we want to keep the errormessage for this or that we check if the Content-Length > 0 and if false ignore the header information on Content-Type and continue without any log message.
My personal opinion is that the error message should stay
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: OpenURL HTTP Response Error parsing json to LUA table

Post by rwblinn »

Thanks for swift reply = will wait the outcome.

Unfortunate do not have influence on the HTTP response.
This is a HTTP RESP-API PUT request to a HomeMatic CCU using the addon CCU-JACK.

In the dzVents script tried to cheat = the item gets changed also shown in the log but same error.

Code: Select all

if (item.isHTTPResponse) then
    local headers = item.headers
    headers['Content-Length'] = "15"
    item.headers = headers
    item['isJSON'] = true
    item['data'] = '{"status":"OK"}'
    domoticz.log(item)
 end

Code: Select all

2021-03-06 10:39:18.870 Status: dzVents: Info: CCUJACK: {["isTimer"]=false, ["isDevice"]=false, ["isSecurity"]=false, ["data"]="{"status":"OK"}", ["callback"]="CCUJACK", ["isScene"]=false, ["ok"]=true, ["baseType"]="httpResponse", ["statusText"]="OK", ["protocol"]="HTTP/1.1", ["headers"]={["Date"]="Sat, 06 Mar 2021 09:39:18 GMT", ["Content-Type"]="application/json", ["Content-Length"]="15"}, ["isGroup"]=false, ["dump"]=function, ["isShellCommandResponse"]=false, ["isCustomEvent"]=false, ["isXML"]=false, ["trigger"]="CCUJACK", ["isHardware"]=false, ["isSystem"]=false, ["_contentType"]="application/json", ["isJSON"]=true, ["isVariable"]=false, ["statusCode"]=200, ["isHTTPResponse"]=true}
2021-03-06 10:39:18.871 Status: dzVents: Info: CCUJACK: ------ Finished ccu_jack
2021-03-06 10:39:18.870 Error: dzVents: Error: (3.1.5) CCUJACK: Error parsing json to LUA table: (invalid json string)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: OpenURL HTTP Response Error parsing json to LUA table

Post by waaren »

rwblinn wrote: Saturday 06 March 2021 10:46 Thanks for swift reply = will wait the outcome.
Result of the discussion is that we will adjust the check and will not show the error when the response is empty or '' .
This will be in one of the next builds (beta)

Just curious. You asked for a callback in the openURL, do you only expect 'a return' or do you expect something specific?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rwblinn
Posts: 72
Joined: Wednesday 10 June 2015 21:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 4
Location: Hamburg (Germany)/Middelburg (NL)
Contact:

Re: OpenURL HTTP Response Error parsing json to LUA table

Post by rwblinn »

That's good news - Thanks a lot.

Regarding your question:
The callback is used to get the status text (dzVents item.statusText) as described in the HomeMatic CCU Addon CCU-JACK documentation:
Result OK: HTTP/1.1 200 OK
Result NOK: Errors are shown in the HTTP-Status
An error could be given if for example a wrong serial number for a device is provided in the HTTP request: "Not Found". 404
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest