Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Added basic auth header #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion check_mk_web_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down