# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import re
import requests
from lxml import etree
import StringIO
import time
import sys
import json
import re
s = requests.session()
print s.headers
username='xxx'
password='65c1978850b7dca18503d8e22073bab0'
login_url = 'http://1.1.1.1/api/logincheck?password=%s&username=%s' %(password,username)
print login_url
data = {'username':username,'password':password}
print data
#data = urllib.urlencode(data)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0'
}
response = s.get(login_url, data=data, headers=headers,timeout=10)
print response
print '--------------------'
print response.status_code
a= response.content
print a
print type(a)
p=re.compile('.*?<token>(.*?)</token>*')
m=p.match(a)
token= m.group(1)
disable_url='http://1.1.1.1/api/ALERT-SERVICE/v1.0/alertExcludes?series_id=1&user_id=%s' %(username)
print disable_url
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0',
'token':token,
'Content-Type':'application/json;charset=utf-8'
}
data = {'userId':username,'classId':3,'className':'可用性监控','excludeId':'378','excludeMode':'1','excludeReason':'null','excludeTime':'yyyy-mm-dd-00-00-00~yyyy-mm-dd-23-59-59','set':'true','systemId':'9103','systemName':'AAAA'}
print data
#data = urllib.urlencode(data)
print data
response = s.put(disable_url, data=json.dumps(data), headers=headers,timeout=10)
print response.content
getstatisurl='http://1.1.1.1/api/ALERT-SERVICE/v1.0/alertExcludes?series_id=1&userId=%s&user_id=%s' %(username,username)
print getstatisurl