# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import urllib
import urllib2
import json
def http_post():
url = 'http://192.168.137.3/zabbix/api_jsonrpc.php'
values = {
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "admin",
"password": "zabbix"
},
"id": 1
}
headers={"Content-Type":"application/json"}
jdata = json.dumps(values) # 对数据进行JSON格式化编码
req = urllib2.Request(url, jdata,headers) # 生成页面请求的完整数据
response = urllib2.urlopen(req) # 发送页面请求
return response.read() # 获取服务器返回的页面信息
resp = http_post()
print resp
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/templates/a8.py
{"jsonrpc":"2.0","result":"dae9c7e96eed20c90327741a7a8c6de1","id":1}