Funktioniert bei mir jetzt mal nicht. :cool:
Sorry - hatte in der Zeile nach dem try ein doppeltes if drin
ABER: ich hab es jetzt getestet und die Routine hat nicht funktioniert, weil sie (natürlich) einen Zertifikatsfehler gemeldet hat.
Ich hab jetzt was eingebaut, damit der Zertifikatsfehler ignoriert wird. Ob das sicher ist sollte jeder selbst entscheiden.
So funktioniert das bei mir (getestet mit dem aktuellen doorpi und fhem), /usr/local/lib/python2.7/dist-packages/doorpi/action/SingleActions/url_call.py
Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
logger = logging.getLogger(__name__)
logger.debug("%s loaded", __name__)
from doorpi.action.base import SingleAction
import doorpi
import urllib2
import ssl
def fire_command(url):
try:
if "@" in url:
upass = url[url.find('://')+3:url.find('@')]
username = upass[:upass.find(':')]
password = upass[upass.find(':')+1:]
url = url[:url.find('://') + 3] + url[url.find('@') + 1:]
url = url.replace(" ", "%20")
#DISCOURAGED!!! IGNORING CERTIFICATE!!!!
ssl._create_default_https_context = ssl._create_unverified_context
p = urllib2.HTTPPasswordMgrWithDefaultRealm()
p.add_password(None, url, username, password)
handler = urllib2.HTTPBasicAuthHandler(p)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
return urllib2.urlopen(
url=url,
data=None,
timeout=1
)
except urllib2.HTTPError as exp:
logger.error('HTTPError: %s - %s' % (exp.code, exp.reason))
except urllib2.URLError as exp:
logger.error('URLError: %s' % exp.reason)
return False
def get(parameters):
parsed_parameters = doorpi.DoorPi().parse_string(parameters)
return UrlCallAction(fire_command, url=parsed_parameters)
class UrlCallAction(SingleAction):
pass
Alles anzeigen