openURL error

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

Moderator: leecollings

Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

openURL error

Post by Maxx »

Hi,

Since the update to the latest Beta (4.11415 ) I am getting error messages with the openURL call. I made a test script:

Code: Select all

return {
	on = {
		timer = {'every minute'},

	},
	execute = function(dz, triggeredItem)
	        local string = 'http://192.168.1.231:8080//json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=12'
	        dz.log(string)
            dz.openURL({
            url = string,
         })
	end
}
it gives the following error:

Code: Select all

2019-11-02 13:54:00.895 Error: Error opening url: http://192.168.1.231:8080//json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=12
it worked without problem before the update.

Did something change with the LUA update?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL error

Post by waaren »


Maxx wrote:Hi,

Since the update to the latest Beta (4.11415 ) I am getting error messages with the openURL call.
Can you try again but with only one / before the JSON ?

Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: openURL error

Post by Maxx »

Same error:

Code: Select all

2019-11-02 19:07:00.990 Error: Error opening url: http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=12
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL error

Post by waaren »

Maxx wrote: Saturday 02 November 2019 19:08 Same error:

Code: Select all

2019-11-02 19:07:00.990 Error: Error opening url: http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=12
I checked this url with domoticz 4.11434 (dzVents 2.5.0) and domoticz 4.11454 (dzVents 2.5.0) but do not see any unexpected behavior
What do you see in the log if you execute this test script ?

Code: Select all

return {
	on = {
		timer = {'every minute'},
		httpResponses = { 'testUrl*' },
	},
	execute = function(dz, item)
		if item.isHTTPResponse then
			dz.utils.dumpTable(item)
			dz.log('Domoticz and dzVents version: ' .. dz.settings.domoticzVersion .. ', ' .. dz.settings.dzVentsVersion,dz.LOG_FORCE)
		else
		    urls =
			{ 	
				["testUrl1"] = 'http://192.168.1.231:8080//json.htm?type=command&param=udevice&idx=109&nvalue=0&svalue=12',
				["testUrl2"] = 'http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=109&nvalue=0&svalue=12', 
				["testUrl3"] = dz.settings['Domoticz url'] .. '//json.htm?type=command&param=udevice&idx=109&nvalue=0&svalue=12' ,
				["testUrl4"] = dz.settings['Domoticz url'] .. '/json.htm?type=command&param=udevice&idx=109&nvalue=0&svalue=12' ,
			}

			for callback, url in pairs(urls) do 
				dz.openURL({ url = url , callback = callback })
			end
		end
	end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: openURL error

Post by Maxx »

Here the log
I changed the device in 2001, wich is an existing device (Dummy custom sensor)

Something else, maybe related, I am using a second domoticz server and I use remote server to share variables. This works fine except with dummy devices. They do not appear in the main device list, all the others do.

The URL call in this case is also to a dummy device..

Code: Select all

 2019-11-03 12:45:03.103 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-11-03 12:45:03.333 Status: dzVents: Info: Handling httpResponse-events for: "testUrl4"
2019-11-03 12:45:03.333 Status: dzVents: Info: ------ Start internal script: Script #2: HTTPResponse: "testUrl4"
2019-11-03 12:45:03.338 Status: dzVents: > baseType: httpResponse
2019-11-03 12:45:03.338 Status: dzVents: > isVariable: false
2019-11-03 12:45:03.338 Status: dzVents: > ok: true
2019-11-03 12:45:03.338 Status: dzVents: > isJSON: true
2019-11-03 12:45:03.338 Status: dzVents: > isSecurity: false
2019-11-03 12:45:03.338 Status: dzVents: > headers:
2019-11-03 12:45:03.338 Status: dzVents: > Pragma: no-cache
2019-11-03 12:45:03.338 Status: dzVents: > Cache-Control: no-cache
2019-11-03 12:45:03.338 Status: dzVents: > Content-Type: application/json;charset=UTF-8
2019-11-03 12:45:03.338 Status: dzVents: > Content-Length: 53
2019-11-03 12:45:03.338 Status: dzVents: > Access-Control-Allow-Origin: *
2019-11-03 12:45:03.338 Status: dzVents: > _contentType: application/json;charset=UTF-8
2019-11-03 12:45:03.338 Status: dzVents: > isGroup: false
2019-11-03 12:45:03.338 Status: dzVents: > statusText: OK
2019-11-03 12:45:03.338 Status: dzVents: > isHTTPResponse: true
2019-11-03 12:45:03.338 Status: dzVents: > isDevice: false
2019-11-03 12:45:03.338 Status: dzVents: > json:
2019-11-03 12:45:03.338 Status: dzVents: > status: OK
2019-11-03 12:45:03.338 Status: dzVents: > title: Update Device
2019-11-03 12:45:03.338 Status: dzVents: > isScene: false
2019-11-03 12:45:03.338 Status: dzVents: > trigger: testUrl4
2019-11-03 12:45:03.338 Status: dzVents: > callback: testUrl4
2019-11-03 12:45:03.338 Status: dzVents: > data: {
2019-11-03 12:45:03.338 "status" : "OK",
2019-11-03 12:45:03.338 "title" : "Update Device"
2019-11-03 12:45:03.338 }
2019-11-03 12:45:03.338
2019-11-03 12:45:03.338 Status: dzVents: > statusCode: 200
2019-11-03 12:45:03.338 Status: dzVents: > isTimer: false
2019-11-03 12:45:03.338 Status: dzVents: > protocol: HTTP/1.1
2019-11-03 12:45:03.338 Status: dzVents: !Info: Domoticz and dzVents version: 4.11415, 2.4.29
2019-11-03 12:45:03.339 Status: dzVents: Info: ------ Finished Script #2
2019-11-03 12:45:03.340 Status: dzVents: Info: Handling httpResponse-events for: "testUrl2"
2019-11-03 12:45:03.340 Status: dzVents: Info: ------ Start internal script: Script #2: HTTPResponse: "testUrl2"
2019-11-03 12:45:03.340 Status: dzVents: > baseType: httpResponse
2019-11-03 12:45:03.340 Status: dzVents: > isVariable: false
2019-11-03 12:45:03.340 Status: dzVents: > ok: true
2019-11-03 12:45:03.340 Status: dzVents: > isJSON: false
2019-11-03 12:45:03.340 Status: dzVents: > isSecurity: false
2019-11-03 12:45:03.340 Status: dzVents: > headers:
2019-11-03 12:45:03.340 Status: dzVents: > _contentType:
2019-11-03 12:45:03.340 Status: dzVents: > isGroup: false
2019-11-03 12:45:03.340 Status: dzVents: > statusText: OK
2019-11-03 12:45:03.341 Status: dzVents: > isHTTPResponse: true
2019-11-03 12:45:03.341 Status: dzVents: > isDevice: false
2019-11-03 12:45:03.341 Status: dzVents: > isScene: false
2019-11-03 12:45:03.341 Status: dzVents: > trigger: testUrl2
2019-11-03 12:45:03.341 Status: dzVents: > callback: testUrl2
2019-11-03 12:45:03.341 Status: dzVents: > data:
2019-11-03 12:45:03.341 Status: dzVents: > statusCode: 200
2019-11-03 12:45:03.341 Status: dzVents: > isTimer: false
2019-11-03 12:45:03.341 Status: dzVents: > protocol: HTTP/1.1
2019-11-03 12:45:03.341 Status: dzVents: !Info: Domoticz and dzVents version: 4.11415, 2.4.29
2019-11-03 12:45:03.343 Status: dzVents: Info: ------ Finished Script #2
2019-11-03 12:45:03.344 Status: dzVents: Info: Handling httpResponse-events for: "testUrl3"
2019-11-03 12:45:03.344 Status: dzVents: Info: ------ Start internal script: Script #2: HTTPResponse: "testUrl3"
2019-11-03 12:45:03.344 Status: dzVents: > baseType: httpResponse
2019-11-03 12:45:03.344 Status: dzVents: > isVariable: false
2019-11-03 12:45:03.344 Status: dzVents: > ok: true
2019-11-03 12:45:03.344 Status: dzVents: > isJSON: false
2019-11-03 12:45:03.344 Status: dzVents: > isSecurity: false
2019-11-03 12:45:03.344 Status: dzVents: > headers:
2019-11-03 12:45:03.344 Status: dzVents: > _contentType:
2019-11-03 12:45:03.344 Status: dzVents: > isGroup: false
2019-11-03 12:45:03.344 Status: dzVents: > statusText: OK
2019-11-03 12:45:03.345 Status: dzVents: > isHTTPResponse: true
2019-11-03 12:45:03.345 Status: dzVents: > isDevice: false
2019-11-03 12:45:03.345 Status: dzVents: > isScene: false
2019-11-03 12:45:03.345 Status: dzVents: > trigger: testUrl3
2019-11-03 12:45:03.345 Status: dzVents: > callback: testUrl3
2019-11-03 12:45:03.345 Status: dzVents: > data:
2019-11-03 12:45:03.345 Status: dzVents: > statusCode: 200
2019-11-03 12:45:03.345 Status: dzVents: > isTimer: false
2019-11-03 12:45:03.345 Status: dzVents: > protocol: HTTP/1.1
2019-11-03 12:45:03.345 Status: dzVents: !Info: Domoticz and dzVents version: 4.11415, 2.4.29
2019-11-03 12:45:03.346 Status: dzVents: Info: ------ Finished Script #2
2019-11-03 12:45:03.346 Status: dzVents: Info: Handling httpResponse-events for: "testUrl1"
2019-11-03 12:45:03.346 Status: dzVents: Info: ------ Start internal script: Script #2: HTTPResponse: "testUrl1"
2019-11-03 12:45:03.346 Status: dzVents: > baseType: httpResponse
2019-11-03 12:45:03.346 Status: dzVents: > isVariable: false
2019-11-03 12:45:03.347 Status: dzVents: > ok: true
2019-11-03 12:45:03.347 Status: dzVents: > isJSON: false
2019-11-03 12:45:03.347 Status: dzVents: > isSecurity: false
2019-11-03 12:45:03.347 Status: dzVents: > headers:
2019-11-03 12:45:03.347 Status: dzVents: > _contentType:
2019-11-03 12:45:03.347 Status: dzVents: > isGroup: false
2019-11-03 12:45:03.347 Status: dzVents: > statusText: OK
2019-11-03 12:45:03.347 Status: dzVents: > isHTTPResponse: true
2019-11-03 12:45:03.347 Status: dzVents: > isDevice: false
2019-11-03 12:45:03.347 Status: dzVents: > isScene: false
2019-11-03 12:45:03.347 Status: dzVents: > trigger: testUrl1
2019-11-03 12:45:03.347 Status: dzVents: > callback: testUrl1
2019-11-03 12:45:03.347 Status: dzVents: > data:
2019-11-03 12:45:03.347 Status: dzVents: > statusCode: 200
2019-11-03 12:45:03.347 Status: dzVents: > isTimer: false
2019-11-03 12:45:03.347 Status: dzVents: > protocol: HTTP/1.1
2019-11-03 12:45:03.347 Status: dzVents: !Info: Domoticz and dzVents version: 4.11415, 2.4.29
2019-11-03 12:45:03.348 Status: dzVents: Info: ------ Finished Script #2
2019-11-03 12:45:03.225 Error: Error opening url: http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=5070&nvalue=0&svalue=983.9
2019-11-03 12:45:03.231 Error: Error opening url: http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=3617&nvalue=0&svalue=132;ZO;35;54;12.8;11.6
2019-11-03 12:45:03.232 Error: Error opening url: http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=3665&nvalue=0&svalue=0;0.9
2019-11-03 12:45:03.234 Error: Error opening url: http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=3749&nvalue=0&svalue=210
2019-11-03 12:45:03.236 Error: Error opening url: http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=3750&nvalue=0&svalue=26300
2019-11-03 12:45:03.238 Error: Error opening url: http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=3751&nvalue=82&svalue= 
Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: openURL error

Post by Maxx »

Hi Waaren,

This line works:

Code: Select all

["testUrl4"] = dz.settings['Domoticz url'] .. '/json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=22'
the others give an error:

Code: Select all

 2019-11-03 13:35:01.529 Error: Error opening url: http://127.0.0.1:8080//json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=15
2019-11-03 13:35:01.533 Error: Error opening url: http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=14
2019-11-03 13:35:01.554 Error: Error opening url: http://192.168.1.231:8080//json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=16
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL error

Post by waaren »

Maxx wrote: Sunday 03 November 2019 12:52 Here the log
I changed the device in 2001, which is an existing device (Dummy custom sensor)

Something else, maybe related, I am using a second domoticz server and I use remote server to share variables. This works fine except with dummy devices. They do not appear in the main device list, all the others do.

The URL call in this case is also to a dummy device..
What I see in the log is that the only testURL working is testUrl4. That url is targeted at the local system.
Is http://192.168.1.231 the same system ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: openURL error

Post by Maxx »

It is the same system.

I was thinking it may have something to do with authentication so I add the username and password but it still give an error

Code: Select all

			["testUrl2"] = 'http://admin:[email protected]:8080/json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=14',
error:

Code: Select all

 2019-11-03 13:58:00.598 Error: Error opening url: http://127.0.0.1:8080//json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=15
2019-11-03 13:58:00.601 Error: Error opening url: http://192.168.1.231:8080//json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=16
2019-11-03 13:58:00.603 Error: Error opening url: http://admin:[email protected]:8080/json.htm?type=command&param=udevice&idx=2001&nvalue=0&svalue=14
2019-11-03 13:58:00.811 Error: dzVents: Error: (2.4.29) HTTP/1.1 response: 401 ==>> Unauthorized 
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL error

Post by waaren »

Maxx wrote: Sunday 03 November 2019 13:59 It is the same system.
can you try below test script after adding 192.168.1.* to the field [ Local Networks (no username/password):] in [system] [setup] [settings]
so that it look something like: 127.0.0.1;192.168.1.*

Code: Select all

return {
	on = {
		timer = {'every minute'},
		httpResponses = { 'testUrl*' },
	},
	execute = function(dz, item)
		if item.isHTTPResponse then
			dz.utils.dumpTable(item)
			dz.log('Domoticz and dzVents version: ' .. dz.settings.domoticzVersion .. ', ' .. dz.settings.dzVentsVersion,dz.LOG_FORCE)
			dz.log('Domoticz url: ' .. dz.settings['Domoticz url'],dz.LOG_FORCE)
		else
		    urls =
			{ 	
				-- ["testUrl1"] = 'http://192.168.1.231:8080//json.htm?type=command&param=udevice&idx=109&nvalue=0&svalue=12',
				-- ["testUrl2"] = 'http://192.168.1.231:8080/json.htm?type=command&param=udevice&idx=109&nvalue=0&svalue=12', 
				-- ["testUrl3"] = dz.settings['Domoticz url'] .. '//json.htm?type=command&param=udevice&idx=109&nvalue=0&svalue=12' ,
				["testUrl4"] = dz.settings['Domoticz url'] .. '/json.htm?type=command&param=udevice&idx=109&nvalue=0&svalue=12' ,
			}

			for callback, url in pairs(urls) do 
				dz.openURL({ url = url , callback = callback })
			end
		end
	end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: openURL error

Post by Maxx »

Spot on, like magic. Works like a charm

What is the story behind this?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL error

Post by waaren »

Maxx wrote: Sunday 03 November 2019 14:21 Spot on, like magic. Works like a charm

What is the story behind this?
By adding the 192.168.1.* you allow all systems from your home network to access domoticz API without a username / password.
Can only tell what the problem was if I know what was in this field before and what the content of your /etc/hosts is .
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: openURL error

Post by Maxx »

/etc/hosts content:

Code: Select all

127.0.0.1	localhost
::1		localhost ip6-localhost ip6-loopback
ff02::1		ip6-allnodes
ff02::2		ip6-allrouters

127.0.1.1	raspberrypi
127.0.0.1 was in the field
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL error

Post by waaren »

Maxx wrote: Sunday 03 November 2019 15:57 127.0.0.1 was in the field
And what was the logline produced by

Code: Select all

dz.log('Domoticz url: ' .. dz.settings['Domoticz url'],dz.LOG_FORCE)
?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: openURL error

Post by Maxx »

2019-11-03 17:22:01.156 Status: dzVents: !Info: Domoticz url: http://127.0.0.1:8080
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL error

Post by waaren »

Maxx wrote: Sunday 03 November 2019 17:23 2019-11-03 17:22:01.156 Status: dzVents: !Info: Domoticz url: http://127.0.0.1:8080
Only things I can think of why it works now and did not do previously is a funny character in the field. 127.0.0.1
or 127.0.1.1 in the /etc/hosts for raspberrypi.
I have this in my /etc/hosts where PI-2 is my 'production' domoticz and PI-6 is test

Code: Select all

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

192.168.192.59          PI-2
192.168.192.109         PI-6
192.168.192.1           R7800
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: openURL error [Solved]

Post by Maxx »

Well, thanks for your time again.

I will have a closer look at the host file options, it looks interesting since I have a production and a test domoticz too
cjb75

Re: openURL error

Post by cjb75 »

I have a similar problem as mentioned in https://www.domoticz.com/forum/viewtopi ... 59&t=24453, my script is below:

Code: Select all

...
if (item.isHTTPResponse and item.ok) then
             if (item.trigger == 'unifi_loggedin') then
                 dz.utils.dumpTable(item)
                 dz.log('Domoticz and dzVents version: ' .. dz.settings.domoticzVersion .. ', ' .. dz.settings.dzVentsVersion,dz.LOG_FORCE)
                 dz.log('Domoticz url: ' .. dz.settings['Domoticz url'],dz.LOG_FORCE)
                 dz.openURL({
                     url = controllerUrl .. 'api/s/defaultd/stat/sta',
                     method = 'GET',
                     callback = 'unifi_data'
                 })
                ...
2020-04-10 17:53:01.691 Status: dzVents: > ok: true
2020-04-10 17:53:01.691 Status: dzVents: > isScene: false
2020-04-10 17:53:01.691 Status: dzVents: > isHTTPResponse: true
2020-04-10 17:53:01.691 Status: dzVents: > statusText: OK
2020-04-10 17:53:01.691 Status: dzVents: > data: {"meta":{"rc":"ok"},"data":[]}
2020-04-10 17:53:01.691 Status: dzVents: > isHardware: false
2020-04-10 17:53:01.691 Status: dzVents: > isSystem: false
2020-04-10 17:53:01.691 Status: dzVents: > isDevice: false
2020-04-10 17:53:01.691 Status: dzVents: > protocol: HTTP/1.1
2020-04-10 17:53:01.691 Status: dzVents: > isJSON: true
2020-04-10 17:53:01.691 Status: dzVents: > json:
2020-04-10 17:53:01.691 Status: dzVents: > meta:
2020-04-10 17:53:01.691 Status: dzVents: > rc: ok
2020-04-10 17:53:01.691 Status: dzVents: > data:
2020-04-10 17:53:01.691 Status: dzVents: > trigger: unifi_loggedin
2020-04-10 17:53:01.691 Status: dzVents: > baseType: httpResponse
2020-04-10 17:53:01.691 Status: dzVents: > isGroup: false
2020-04-10 17:53:01.691 Status: dzVents: > isCustomEvent: false
2020-04-10 17:53:01.691 Status: dzVents: > isSecurity: false
2020-04-10 17:53:01.691 Status: dzVents: > statusCode: 200
2020-04-10 17:53:01.691 Status: dzVents: > isXML: false
2020-04-10 17:53:01.691 Status: dzVents: > isVariable: false
2020-04-10 17:53:01.691 Status: dzVents: > isTimer: false
2020-04-10 17:53:01.691 Status: dzVents: > callback: unifi_loggedin
2020-04-10 17:53:01.691 Status: dzVents: > _contentType: application/json;charset=UTF-8
2020-04-10 17:53:01.691 Status: dzVents: > headers:
2020-04-10 17:53:01.691 Status: dzVents: > Set-Cookie: csrf_token=YLCVpUUrdJMNvLaX0mgpM3Hj7xlHETHj; Path=/; Secure
2020-04-10 17:53:01.691 Status: dzVents: > Date: Fri, 10 Apr 2020 15:53:01 GMT
2020-04-10 17:53:01.691 Status: dzVents: > Content-Type: application/json;charset=UTF-8
2020-04-10 17:53:01.691 Status: dzVents: > Access-Control-Expose-Headers: Access-Control-Allow-Origin,Access-Control-Allow-Credentials
2020-04-10 17:53:01.691 Status: dzVents: > Content-Length: 30
2020-04-10 17:53:01.691 Status: dzVents: > Access-Control-Allow-Credentials: true
2020-04-10 17:53:01.691 Status: dzVents: > vary: Origin
2020-04-10 17:53:01.691 Status: dzVents: > X-Frame-Options: DENY
2020-04-10 17:53:01.691 Status: dzVents: !Info: Domoticz and dzVents version: 2020.1, 3.0.1
2020-04-10 17:53:01.691 Status: dzVents: !Info: Domoticz url: http://127.0.0.1:8080
2020-04-10 17:53:02.315 Error: Error opening url: https://192.168.0.2:8443/api/s/default/stat/sta
2020-04-10 17:53:02.518 Error: dzVents: Error: (3.0.1) HTTP/1.1 response: 401 ==>> No reason returned!

My /etc/hosts file:

Code: Select all

127.0.0.1       localhost
Any help would be really appreciated!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL error

Post by waaren »

cjb75 wrote: Friday 10 April 2020 17:56

Code: Select all

2020-04-10 17:53:02.315 Error: Error opening url: https://192.168.0.2:8443/api/s/default/stat/sta
2020-04-10 17:53:02.518 Error: dzVents: Error: (3.0.1) HTTP/1.1 response: 401 ==>> No reason returned!
Any help would be really appreciated!
looks like you are not authorized.
What do you see when sending the same using curl ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
cjb75

Re: openURL error

Post by cjb75 »

I think I'm authorized since
if (item.isHTTPResponse and item.ok) then
and
if (item.trigger == 'unifi_loggedin') then
seems to be true.

See code below:

Code: Select all

if (item.isTimer or item.isDevice) then
             dz.openURL({
                 url = controllerUrl .. 'api/login',
                 method = 'POST',
                 postData = {
                     ['password'] = controllerPassword,
                     ['username'] = controllerLogin
                 },
                 callback = 'unifi_loggedin'
             })
         end
 
         if (item.isHTTPResponse and item.ok) then
             if (item.trigger == 'unifi_loggedin') then
                 dz.utils.dumpTable(item)
                 dz.log('Domoticz and dzVents version: ' .. dz.settings.domoticzVersion .. ', ' .. dz.        settings.dzVentsVersion,dz.LOG_FORCE)
 
                 dz.log('Domoticz url: ' .. dz.settings['Domoticz url'],dz.LOG_FORCE)
                 dz.openURL({
                     url = controllerUrl .. 'api/s/default/stat/sta',
                     method = 'GET',
                     callback = 'unifi_data'
                 })
I'm not sure how to use curl but using the command:
curl --cookie /tmp/unifi_cookie --cookie-jar /tmp/unifi_cookie --insecure -X POST -d '{"password":"mypassword","username":"domoticz"}' https://192.168.0.2:8443/api/login
followed by:
curl --cookie /tmp/unifi_cookie --cookie-jar /tmp/unifi_cookie --insecure --data "json={}" https://192.168.0.2:8443/api/s/default/stat/sta
works for me
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL error

Post by waaren »

cjb75 wrote: Friday 10 April 2020 19:23 I think I'm authorized since
if (item.isHTTPResponse and item.ok) then
and
if (item.trigger == 'unifi_loggedin') then
seems to be true.
You are authorized to send the first one but the error you see is the return of the seconds openURL. I never managed to send something to a URL where a cookie is required from domoticz using dz.openURL
Probably the quickest way to success here is to use os.execute(cmd) with the curl as cmd.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests