Host not found (authoritative) - Help

Python and python framework

Moderator: leecollings

Post Reply
Xorfor

Host not found (authoritative) - Help

Post by Xorfor »

I want to create a Winddelen plugin, because the standard Winddelen from Domoticz not using all possibilities from the give API. I like to use links like:

https://zep-api.windcentrale.nl/production/1

or

https://zep-api.windcentrale.nl/production/1/live

But when I define a connection with:

Code: Select all

self.httpConn = Domoticz.Connection(Name="HTTP Test", Transport="TCP/IP", Protocol="HTTP", Address="zep-api.windcentrale.nl")
I get:

Host not found (authoritative)

As you can see the links above gives you data, but I can not use Domoticz.Connection, because I have to specify a domain. And https://zep-api.windcentrale.nl gives a Login page :(

How can I solve this?
Xorfor

Re: Host not found (authoritative) - Help

Post by Xorfor »

I tried already (I think almost) everything, but nothing works.

Finally I tried to get a workaround to use urllib.request.

But a soon as I place 'import urllib.request' in the Python plugin, Domoticz stops working after a restart!

Or if I enter 'import urllib', i get:

2017-12-27 23:39:58.988 Error: (motion) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/motion/:/usr/lib/python35.zip:/usr/lib/python3.5:/usr/lib/python3.5/plat-arm-linux-gnueabihf:/usr/lib/python3.5/lib-dynload'.
2017-12-27 23:39:58.988 Error: (Motion detected) Module Import failed, exception: 'NameError'
2017-12-27 23:39:58.988 Error: (Motion detected) Error Line details not available.
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Host not found (authoritative) - Help

Post by Dnpwwo »

@Xorfor,

Can you post a bit more of you plugin? That would help.

Also if you execute:

Code: Select all

nslookup zep-api.windcentrale.nl
from the command line on the machine you are using what do you see?
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Xorfor

Re: Host not found (authoritative) - Help

Post by Xorfor »

@Dnpwwo


The code can be found on: https://github.com/Xorfor/Domoticz/tree ... ndcentrale

Nslookup gives:

Code: Select all

nslookup zep-api.windcentrale.nl
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
zep-api.windcentrale.nl canonical name = zep-prod-lb-https-167027908.eu-central-1.elb.amazonaws.com.
Name:   zep-prod-lb-https-167027908.eu-central-1.elb.amazonaws.com
Address: 54.93.73.206
Name:   zep-prod-lb-https-167027908.eu-central-1.elb.amazonaws.com
Address: 52.29.46.1
Name:   zep-prod-lb-https-167027908.eu-central-1.elb.amazonaws.com
Address: 52.59.60.130
Name:   zep-prod-lb-https-167027908.eu-central-1.elb.amazonaws.com
Address: 52.29.184.187
Curl gives me exactly the result I want:

Code: Select all

 curl https://zep-api.windcentrale.nl/production/1/live
{"powerProducerId":"f588ce00-92ee-45ee-b480-f7d6df204034","windSpeed":5.0,"windDirection":"ZO","powerAbsTot":764.0,"powerAbsWd":78.0,"powerRel":33.0,"diameter":41.0,"rpm":17.5,"pulsating":false,"kwh":4434603.0,"kwhForecast":4955000.0,"hoursRunThisYear":8264.0833333333,"runPercentage":94.4425778631072,"windSpeedForecast":5.0,"windDirectionForecast":"ZW","timestamp":"2017-12-29T17:53:37"}
At this moment I get timeouts:

Code: Select all

2017-12-29 17:56:07.407 (De Grote Geert) onHeartbeat called, run again in 17 heartbeats. 
2017-12-29 17:56:08.259 (De Grote Geert) Calling message handler 'onConnect'. 
2017-12-29 17:56:08.260 (De Grote Geert) onConnect called (110): Connection timed out 
2017-12-29 17:56:08.260 Error: (De Grote Geert) Failed to connect (110) to: zep-api.windcentrale.nl with error: Connection timed out 
2017-12-29 17:56:17.381 (De Grote Geert) Calling message handler 'onHeartbeat'. 
2017-12-29 17:56:17.381 (De Grote Geert) onHeartbeat called 
Please let me know if you need more information.
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Host not found (authoritative) - Help

Post by Dnpwwo »

@Xorfor,

Looks like you have solved your initial problem.

From looking at your plugin I see you have realised that you need to use HTTPS not HTTP and you have (somehow) discovered that Domoticz has undocumented support for client side HTTPS. This is alpha quality only so please don't use it on your production instance. This can crash Domoticz during disconnection.

I'm interested though, did it work for you :?:
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Xorfor

Re: Host not found (authoritative) - Help

Post by Xorfor »

@Dnpwwo,

No I gave up :( .

In a 'normal' simple python script, I can write something like this:

Code: Select all

import urllib.request, json 
    with urllib.request.urlopen("https://zep-api.windcentrale.nl/production/1/live") as url:
        data = json.loads(url.read().decode())
        print(data)
That works. But in a plugin, whatever I try, such a 'simple' request doesn't work.

1. With the code as it is now on https://github.com/Xorfor/Domoticz/blob ... /plugin.py, I get 'Connection timed out'
2. To avoid Domoticz.Connect problems, I tried to add 'import urllib.request'. But then Domoticz even doesn't startup!!! A conflict between Domoticz and urllib?
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Host not found (authoritative) - Help

Post by Dnpwwo »

@Xorfor,

I had another look at your code and found your main problem is that you haven't told the 'Connect' what port to use. I've added an error check to Domoticz to report that in future.

Once I added 'Port="443"' it started working. The 'Data' parameter to onMessage is a dictionary for HTTP which you can iterate and I got this in the log:
Spoiler: show
2018-01-01 13:56:01.552 (HTTPS Test) Started.
2018-01-01 13:56:01.647 (HTTPS Test) Entering work loop.
2018-01-01 13:56:01.647 (HTTPS Test) Initialized version 1.0.0, author 'Xorfor'
2018-01-01 13:56:02.830 Plugin: TLS Certificate found: '/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root'
2018-01-01 13:56:02.830 Plugin: TLS Certificate found: '/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root'
2018-01-01 13:56:02.831 Plugin: TLS Certificate found: '/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority'
2018-01-01 13:56:02.832 Plugin: TLS Certificate found: '/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA'
2018-01-01 13:56:02.832 Plugin: TLS Certificate found: '/OU=Domain Control Validated/OU=PositiveSSL Wildcard/CN=*.windcentrale.nl'
2018-01-01 13:56:03.561 (HTTPS Test) HTTP Details (3):
2018-01-01 13:56:03.562 (HTTPS Test) --->'Headers (10):
2018-01-01 13:56:03.563 (HTTPS Test) ------->'Connection':'keep-alive'
2018-01-01 13:56:03.564 (HTTPS Test) ------->'Access-Control-Allow-Origin':'*'
2018-01-01 13:56:03.565 (HTTPS Test) ------->'Access-Control-Allow-Headers':'X-Requested-With, Accept, Content-Type, Authorization'
2018-01-01 13:56:03.566 (HTTPS Test) ------->'X-Application-Context':'application:prod:8200'
2018-01-01 13:56:03.567 (HTTPS Test) ------->'Date':'Mon, 01 Jan 2018 02:56:02 GMT'
2018-01-01 13:56:03.568 (HTTPS Test) ------->'Server':'Apache-Coyote/1.1'
2018-01-01 13:56:03.569 (HTTPS Test) ------->'Content-Type':'application/json;charset=UTF-8'
2018-01-01 13:56:03.569 (HTTPS Test) ------->'Access-Control-Allow-Methods':'POST, GET, PUT, PATCH, DELETE, OPTIONS'
2018-01-01 13:56:03.570 (HTTPS Test) ------->'Access-Control-Max-Age':'3600'
2018-01-01 13:56:03.571 (HTTPS Test) ------->'transfer-encoding':'chunked'
2018-01-01 13:56:03.572 (HTTPS Test) --->'Status':'200'
2018-01-01 13:56:03.573 (HTTPS Test) --->'Data':'b'{"powerProducerId":"f588ce00-92ee-45ee-b480-f7d6df204034","windSpeed":6.0,"windDirection":"Z","powerAbsTot":2386.0,"powerAbsWd":241.0,"powerRel":101.0,"diameter":100.0,"rpm":22.1,"pulsating":false,"kwh":7266.0,"kwhForecast":4955000.0,"hoursRunThisYear":3.4833333333372,"runPercentage":94.4517083485457,"windSpeedForecast":4.0,"windDirectionForecast":"ZW","timestamp":"2018-01-01T03:55:30"}''
I needed to tweak the headers in your HTTP request because the site was rejecting the request with a 406 error, I just hit it from Firefox (which worked) then inspected the headers it was sending and copied some of them.

Have a look at the updated source here.
plugin.py.txt
(8.5 KiB) Downloaded 102 times
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Xorfor

Re: Host not found (authoritative) - Help

Post by Xorfor »

@Dnpwwo,

Thanks a lot for your help. I also tried 'Port="443"', but I didn't look any further :( .

I am working now on this plugin. I expect to finish this at the end of the week.
Xorfor

Re: Host not found (authoritative) - Help

Post by Xorfor »

@Dnpwwo,

FYI:

HTTPS works. But what I see, is a memory leakage? As soon as I start the Windcentrale plugin, the memory usage on the RPi is increasing (approx. 10% per day) and finally the Domoticz url does not respond. When I remove the Windcentrale in Hardware, the increasing memory usage stops.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest