python3.3 User.login method to obtain authentication results for Zabbix server

Source: Internet
Author: User

# User.login method gets Zabbix server's authentication result
#!/usr/bin/env python2.7
#coding =utf-8
Import JSON
Import Urllib.request
Import urllib.error
# based URL and required header
URL = "Http://192.168.29.130/zabbix/api_ jsonrpc.php "
Header = {" Content-type ":" Application/json "}
# Auth user and password
data = Json.dumps (
{
"JSONRPC": "2.0",
"method": "User.login",
"params": {
"user": "Admin",
"password": "Zabbix"
}, "id": 0
}
)
data = bytes (data, ' UTF8 ')
# Create request object
Request = urllib.request.Request (URL, Data)
for key in header:
Request.add_header (Key,header[key])
# auth and get Authid
Try:
result = Urllib. Request.urlopen (Request)
res = Result.read (). Decode (' Utf-8 ')
except Urllib.error.URLError as E:
Print (" Auth Failed, please Check Your Name andpassword: ", E.code)
Else:
Response = json.loads (res)
Result.close ()
Print ("Auth successful. The Auth ID is: ", response[' result ')

python3.3 User.login method obtains authentication results for Zabbix server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.