#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Stav archivnich storu MailStore pres Management API (GetStores).""" import json, ssl, urllib.request, urllib.parse from base64 import b64encode MS_HOST="192.168.1.53"; API_PORT=8463 MS_USER="admin"; MS_PASS='*$N(B)vMUym!%' ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE auth=b64encode(f"{MS_USER}:{MS_PASS}".encode()).decode() def call(fn, **params): url=f"https://{MS_HOST}:{API_PORT}/api/invoke/{fn}" data=urllib.parse.urlencode(params).encode() if params else b"" req=urllib.request.Request(url, data=data, headers={"Authorization":f"Basic {auth}"}) with urllib.request.urlopen(req, context=ctx, timeout=30) as r: return json.loads(r.read().decode("utf-8-sig")) for fn in ("GetStores", "GetServerInfo"): try: print(f"===== {fn} =====") print(json.dumps(call(fn), indent=2, ensure_ascii=False)[:2500]) except Exception as ex: print(f"{fn}: CHYBA {type(ex).__name__}: {ex}")