• python 发送大Json格式数据


    # !/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='015208'
    password='65c1978850b7dca18503d8e22073bab0'
    login_url = 'http://1.1.1.51/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)
    getstatisurl='http://1.1.1.51/api/ALERT-SERVICE/v1.0/alertExcludes?series_id=1&userId=%s&user_id=%s' %(username,username)
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0',
        'token':token
         }
    c= s.get(getstatisurl,headers=headers).content
    print type(c)
    print c
    d=json.loads(c)
    print d
    print type(d)
    print '-------------------------------------'
    for i in range(len(d['data'])):
        e=d['data'][i]
        print e
    disable_url='http://1.1.1.51/api/ALERT-SERVICE/v1.0/batchAlertExcludes?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 = [{"excludeId":251,"systemId":9103,"systemName":"AAAA","systemFullName":"AAAA","classId":2,"className"
    :"业务监控","excludeMode":1,"excludeTime":'yyyy-mm-dd-00-00-00~yyyy-mm-dd-23-59-59',"excludeReason":'null'
    ,"lcd":1553233034000,"userId":"006727","set":'true',"diytext":"006727业务监控AAAAAAAA未屏蔽"},{"excludeId":378
    ,"systemId":9103,"systemName":"AAAA","systemFullName":"AAAA","classId":3,"className":"可用性监控","excludeMode"
    :1,"excludeTime":"yyyy-mm-dd-00-00-00~yyyy-mm-dd-23-59-59","excludeReason":'null',"lcd":1553233248000,"userId"
    :"015208","set":'true',"diytext":"015208可用性监控AAAAAAAA未屏蔽"},{"excludeId":1013,"systemId":9103,"systemName"
    :"AAAA","systemFullName":"AAAA","classId":8,"className":"主机","excludeMode":1,"excludeTime":'yyyy-mm-dd-00-00-00~yyyy-mm-dd-23-59-59',"excludeReason":'null',"lcd":1553233248000,"userId":"006727","set":'true',"diytext"
    :"006727主机AAAAAAAA未屏蔽"},{"excludeId":1021,"systemId":6747,"systemName":"ESB","systemFullName":"ESB","classId"
    :9,"className":"进程","excludeMode":1,"excludeTime":'yyyy-mm-dd-00-00-00~yyyy-mm-dd-23-59-59',"excludeReason"
    :'null',"lcd":1537425047000,"userId":"AUTO-KJL","set":'true',"diytext":"AUTO-KJL进程ESBESB未屏蔽"}]
    #data = urllib.urlencode(data)
    print data
    response = s.post(disable_url, data=json.dumps(data), headers=headers,timeout=10)
    print response.content
    getstatisurl='http://1.1.1.51/api/ALERT-SERVICE/v1.0/alertExcludes?series_id=1&userId=%s&user_id=%s' %(username,username)
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0',
        'token':token
         }
    c= s.get(getstatisurl,headers=headers).content
    print type(c)
    print c
    d=json.loads(c)
    print d
    print type(d)
    print '-------------------------------------'
    for i in range(len(d['data'])):
        e=d['data'][i]
        print str(e).decode('unicode-escape')
     # for x in d['data'][i]:
     #    print x,d['data'][i][x]

  • 相关阅读:
    zend studio中安装Emmet插件后迅速编写html的方法
    ZendStudio 代码调试
    PHP中循环结构之foreach循环语句
    【题解】物流运输 [ZJ2006] [P1772] [BZOJ1003]
    【题解】最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052]
    【题解】最长递增路径 [51nod1274]
    【题解】与查询 [51nod1406]
    【题解】选数字 [51nod1354]
    【题解】逆序排列 [51nod1020]
    【题解】整数划分 [51nod1201] 整数划分 V2 [51nod1259]
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348814.html
Copyright © 2020-2023  润新知