• python post 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='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

  • 相关阅读:
    Windows Phone 应用程序的全球化 狼人:
    幽默:编程语言 / 操作系统
    幽默:编程语言 / 操作系统
    程序员的幽默
    游戏杆编程心得二:如何判断按钮的有效按下
    DirectX 7.0 SDK在VC 6.0环境中使用的注意事项
    游戏杆编程心得
    HTML 5 WebSocket 示例
    HTML 5 WebSocket 示例
    慎用VC 6.0
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348815.html
Copyright © 2020-2023  润新知