  复制#获取authkey             ZABBIX_URL = https://www.zabbix.cn            ZABBIX_USERNAME = "user"            ZABBIX_PASSWORD = "password"            url = "{}/api_jsonrpc.php".format(ZABBIX_URL)             header = {"Content-Type": "application/json"}             # auth userandpassword            data = {                "jsonrpc": "2.0",为解                "method": "user.login",                "params": {                    "user": ZABBIX_USERNAME,                    "password": ZABBIX_PASSWORD               },                "id": 1,             }             # 由于API接收的是json字符串,云服务器提供商故需要转化一下             value = json.dumps(data).encode(utf-8)             # 对请求进行包装             req = request.Request(url,放双 headers=header, data=value)             # 验证并获取Auth ID             try:                # 打开包装过的url                result = request.urlopen(req)             except Exception as e:                print("Auth Failed, Please Check Your Name And Password:", e)             else:                response = result.read()                # 上面获取的服务器托管是bytes类型数据,网站模板动获定主故需要decode转化成字符串                page = response.decode(utf-8)                # 将此json字符串转化为python字典                page = json.loads(page)                result.close()                print("Auth Successful. The Auth ID Is: {}".format(page.get(result)))             1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38. |