Skip to content

Commit

Permalink
Merge pull request #22 from slallemand/master
Browse files Browse the repository at this point in the history
fix basic auth (domoticz new version)
  • Loading branch information
s0nik42 authored Mar 4, 2023
2 parents c567e24 + c1d9d43 commit 7a71f1e
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions veolia-idf-domoticz.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,28 +825,19 @@ def __init__(self, config_dict, super_print, debug=False):
retries=1, timeout=int(str(self.configuration["timeout"]))
)

self.headers = urllib3.make_headers()

def open_url(self, uri, data=None): # pylint: disable=unused-argument
# Generate URL
url_test = str(self.configuration["domoticz_server"]) + uri

# Add Authentication Items if needed
if self.configuration["domoticz_login"] != "":
b64domoticz_login = base64.b64encode(
str(self.configuration["domoticz_login"]).encode()
)
b64domoticz_password = base64.b64encode(
str(self.configuration["domoticz_password"]).encode()
)
url_test = (
url_test
+ "&username="
+ b64domoticz_login.decode()
+ "&password="
+ b64domoticz_password.decode()
)
if self.configuration["domoticz_login"] != "" and self.configuration["domoticz_password"] != "":
http_auth = ':'.join((self.configuration["domoticz_login"] , self.configuration["domoticz_password"] ))

self.headers.update(urllib3.make_headers(basic_auth=http_auth))

try:
response = self.__http.request("GET", url_test)
response = self.__http.request("GET", url_test, headers=self.headers)
except urllib3.exceptions.MaxRetryError as e:
# HANDLE CONNECTIVITY ERROR
raise RuntimeError("url=" + url_test + " : " + str(e))
Expand Down

0 comments on commit 7a71f1e

Please sign in to comment.