zoukankan      html  css  js  c++  java
  • 从接口自动化测试框架设计到开发(七)--cookie处理

    模拟登陆获取cookie

    # -*- coding: utf-8 -*-
    # @Author: jiujiu
    # @Date:   2020-03-09 17:05:13
    # @Last Modified time: 2020-03-09 17:37:03
    import requests
    import json
    url = "http://10.1.30.118:3200/provider/user/user/login"
    data = {
        'loginName':'15519560000',
        'loginModel':'0',
        'password':'12345678',
        'loginType':'01',
        'timeStamp':'1582616038764'
        }
    res = requests.post(url,data).json()
    json.dumps(res,sort_keys=True,indent=10)
    print(res['data']['token'])

    运行结果

     简单的通过登录获取token,再通过添加token get到数据

    # -*- coding: utf-8 -*-
    # @Author: jiujiu
    # @Date:   2020-03-09 17:05:13
    # @Last Modified time: 2020-03-11 15:38:42
    import requests
    import json
    def login():
            url = "http://10.1.30.119:9005/user/login"
            data = {
                'loginName': '012345',
                'password': '123456',
                'loginType': '01',
                'loginModel': '0',
                'anti_cache': '1583909753278'
                }
            res = requests.post(url,data=data).json()
                # json.dumps(res,sort_keys=False,indent=1,ensure_ascii=False)
                # token = res['data']['token']
    #token = requests.utils.dict_from_cookiejar(token)
            # print(res)
            token = res['data']['token']
            # print(token)
            return token
    login()
    
    def get_data():
        print({'token':login()})
        url = "http://10.1.30.119:9005/query/selectDriverInfo?current=1&size=20&total=18&car_type=%E5%A4%A7%E5%9E%8B%E5%AE%A2%E8%BD%A6&sex=&time=&screenFiled=&deal_time_s=&deal_time_e=&anti_cache=1583909895350"
        header = {
        'token':login()
        }
        res = requests.get(url=url,headers=header)
        print(res.text)
    if __name__ == '__main__':
        get_data()

    运行结果:

  • 相关阅读:
    ubuntu 16.04 tmux
    ubuntu 16.04 samba 文件共享
    ubuntu 16.04 有道词典
    ubuntu bless 16字节每行
    Win7任务栏图标大小调整为等宽
    ubuntu 16.04 vnc server
    ubuntu 16.04 U盘多媒体不自动弹出
    Linux录屏软件
    通过apt-get安装nvidia驱动
    调试X Server
  • 原文地址:https://www.cnblogs.com/dydxw/p/12449958.html
Copyright © 2011-2022 走看看