From 58e1a1dd4a4ce39fca7ecf957c745e2a35ec0c06 Mon Sep 17 00:00:00 2001 From: Udbv Date: Fri, 10 Jul 2020 14:00:19 +0300 Subject: [PATCH] Added basic auth header --- check_mk_web_api/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/check_mk_web_api/__init__.py b/check_mk_web_api/__init__.py index 8b31153..436c27f 100644 --- a/check_mk_web_api/__init__.py +++ b/check_mk_web_api/__init__.py @@ -126,7 +126,12 @@ def make_request(self, action, query_params=None, data=None): action (str): Action request, e.g. add_host query_params (dict): dict of path parameters data (dict): dict that will be sent as request body - + # Basic Auth + password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() + password_mgr.add_password(None, self.web_api_base, self.username, self.secret) + handler = urllib.request.HTTPBasicAuthHandler(password_mgr) + opener = urllib.request.build_opener(handler) + urllib.request.install_opener(opener) # Raises CheckMkWebApiResponseException: Raised when the HTTP status code != 200 CheckMkWebApiException: Raised when the action's result_code != 0