Page 1 of 1
Wiki Script, don't work "Python - Monitor Domoticz IP address"
Posted: Friday 18 December 2020 10:52
by bjornsundberg
Hi,
I Need to have a IP discovery script and "Python - Monitor Domoticz IP address" looks fine but it dosent work. I think urllib2 is the problem.
Any tips on how to get this to work:
https://www.domoticz.com/wiki/Python_-_ ... IP_address
Re: Wiki Script, don't work "Python - Monitor Domoticz IP address"
Posted: Friday 18 December 2020 20:47
by waaren
bjornsundberg wrote: ↑Friday 18 December 2020 10:52
I Need to have a IP discovery script and "Python - Monitor Domoticz IP address" looks fine but it dosent work. I think urllib2 is the problem.
The port number was missing from this python script and the script is written for python2. I now updated the wiki script to include the port number and also added a version that works with python3. (converted from the original using the 2to3 tool (sudo apt install 2to3) )
I tested them successfully on my systems but if it still not OK for you, please include the errors when executed from the command line.
Re: Wiki Script, don't work "Python - Monitor Domoticz IP address"
Posted: Sunday 20 December 2020 16:10
by erem
IMHO that script has no purpose.
you publish the new ip address to a sensor you can no longer read, since the ip address has changed.
much better would be an email with the new ip address.
better use a portscanner and scan your network for open port 8080, or whatever port you use. NMAP is a good portscanner
just my S.02
Re: Wiki Script, don't work "Python - Monitor Domoticz IP address"
Posted: Sunday 20 December 2020 19:16
by bjornsundberg
erem wrote: ↑Sunday 20 December 2020 16:10
IMHO that script has no purpose.
you publish the new ip address to a sensor you can no longer read, since the ip address has changed.
much better would be an email with the new ip address.
better use a portscanner and scan your network for open port 8080, or whatever port you use. NMAP is a good portscanner
just my S.02
Hi, Sorry for not explaining. I will use it to publish to a mqtt broker that recieves the IP adress. Do you know how to fix the script?
Re: Wiki Script, don't work "Python - Monitor Domoticz IP address"
Posted: Sunday 20 December 2020 23:30
by waaren
bjornsundberg wrote: ↑Sunday 20 December 2020 19:16
Hi, Sorry for not explaining. I will use it to publish to a mqtt broker that recieves the IP adress. Do you know how to fix the script?
I fixed the script on the wiki page.
Re: Wiki Script, don't work "Python - Monitor Domoticz IP address"
Posted: Monday 21 December 2020 22:18
by bjornsundberg
waaren wrote: ↑Friday 18 December 2020 20:47
bjornsundberg wrote: ↑Friday 18 December 2020 10:52
I Need to have a IP discovery script and "Python - Monitor Domoticz IP address" looks fine but it dosent work. I think urllib2 is the problem.
The port number was missing from this python script and the script is written for python2. I now updated the wiki script to include the port number and also added a version that works with python3. (converted from the original using the 2to3 tool (sudo apt install 2to3) )
I tested them successfully on my systems but if it still not OK for you, please include the errors when executed from the command line.
Hi,
Just tested with python3 script but this is the results:
pi@raspberrypi:~/domoticz/scripts/python $ python ip_address.py
Traceback (most recent call last):
File "ip_address.py", line 8, in <module>
import urllib.request, urllib.error, urllib.parse
ImportError: No module named request
pi@raspberrypi:~/domoticz/scripts/python $
Re: Wiki Script, don't work "Python - Monitor Domoticz IP address"
Posted: Monday 21 December 2020 23:09
by waaren
bjornsundberg wrote: ↑Monday 21 December 2020 22:18
Just tested with python3 script but this is the results:
pi@raspberrypi:~/domoticz/scripts/python $ python ip_address.py
did you try
after removing the first (shebang) line of the scripts ?
what do you see when entering
Code: Select all
python --version
python3 --version
python2 --version
Re: Wiki Script, don't work "Python - Monitor Domoticz IP address"
Posted: Tuesday 22 December 2020 18:58
by bjornsundberg
Hi again,
Code: Select all
Version of Python:
pi@RPi3:~/domoticz/scripts/python $ python --version
Python 2.7.16
pi@RPi3:~/domoticz/scripts/python $ python3 --version
Python 3.7.3
pi@RPi3:~/domoticz/scripts/python $ python2 --version
Python 2.7.16
pi@RPi3:~/domoticz/scripts/python $
Running "python3 ip_address.py"
Code: Select all
pi@RPi3:~/domoticz/scripts/python $ python3 ip_address.py
Traceback (most recent call last):
File "ip_address.py", line 27, in <module>
json_object = json.loads(domoticzrequest(domoticzurl)) # retrieve sensor data
File "ip_address.py", line 22, in domoticzrequest
response = urllib.request.urlopen(request)
File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.7/urllib/request.py", line 531, in open
response = meth(req, response)
File "/usr/lib/python3.7/urllib/request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.7/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/usr/lib/python3.7/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Unauthorized
pi@RPi3:~/domoticz/scripts/python $
br
Björn
Re: Wiki Script, don't work "Python - Monitor Domoticz IP address"
Posted: Wednesday 23 December 2020 0:08
by waaren
bjornsundberg wrote: ↑Tuesday 22 December 2020 18:58
Code: Select all
urllib.error.HTTPError: HTTP Error 401: Unauthorized
Seems to be an authorisation issue. (are you authorized to access domoticz without password?)
Make sure that in the Security section in the settings (Setup > Settings > System > Local Networks (no username/password) you allow 127.0.0.1 (and / or ::1 when using IPv6 ) to not need a password.