• python+requests----登录接口reponse中token传递给其他接口使用的一个简单小示例介绍


    #!/usr/bin/env python
    # coding=UTF-8
    import requests
    
    def login():
        url = "https://xxxx.xxx.xxx/v2/user/login"   #因涉及到公司域名隐私,因此使用了xxx
        data = {
            "mobile": "12606666333",
            "password": "33a7d3da476a32ac237b3f603a1be62fad00299e0d4b5a8db8d913104edec629"
        }
        headers = {
            "version": "2.3.0",
            "version-id": "235",
            "device-id": "8BAFD18C-61E3-4BAF-8AB1-0BC16E567633",
            "time": "1557728866628",
            "channel-id": "001",
            "os": "ios",
            "Accept-Language": "zh-tw",
            "device-name": "iPhoneX",
            "User-Agent": "iBer/235 CFNetwork/976 Darwin/18.2.0",
            #注:一定不能加content-type,否则报签名错误
            # Content-Type: multipart/form-data; boundary=vHsPJ5s6grMzpmWoZxd3T3o6.LcUWBvUUu0gDNubaf05Ve7kv6bAkH3s_rr0AEc2D6AbEh
            "sign": "a81b4379f504f330e83792ce2015e629"
        }
    
        r = requests.post(url=url, data=data, headers=headers, verify=False)
        #global uuid,token,version,version_id
        global uuid
        uuid = str(r.json()["data"]["uuid"])
        global token
        token = str(r.json()["data"]["token"])
        version = "2.2.1"
        version_id = "232"
        print "登录成功,如下是reponse返回的内容"
        print r.text
    
        #print uuid,token,version,version_id
    
    def test_create_todo():
        url = "https://xxxx.xxx.xxx/v2/todo/create"
        data = {
            "name": "1239",
            "todo_remind_type": "0",
            "cate_uuid":"86799e50d9890ade579c4ac88059a5ff",
            "all_day":"1",
            "todo_start":"2019-05-13",
            "todo_end":"",
            "type":"0",
            "repeat_tyep":"0",
            "c_user_uuid":""
        }
        headers = {
            "version": "2.3.0",
            "version-id": "235",
            "os": "ios",
            "sign": "123456",
            "is-test":"1",
            "uuid":uuid,
            "token":token
        }
        print uuid
        print token
        r = requests.post(url=url, data=data, headers=headers, verify=False)
        print "%%%%%%%%%%%%%%%%%%"
        print r.json()
    
    login()
    test_create_todo()

    测试结果:

     

    注:使用postman工具的执行步骤,可参考此链接:https://www.cnblogs.com/syw20170419/p/10858645.html

  • 相关阅读:
    Symfony2 多bundle及实体获取,app_dev及app下调试
    Symfony2 WebService(一) 配置篇
    Symfony2 数据调用常用方法
    Symfony2 配置自己的log日志、使用配置文件定义全局常量
    Symfony2 环境及基本命令
    Asterisk拨号函数Dial()详解
    C语言系统资源控制(getrlimit && setrlimit)
    centos FTP服务器的架设和配置
    MYSQL远程登录权限设置
    SIP keepalive方法
  • 原文地址:https://www.cnblogs.com/syw20170419/p/10858708.html
Copyright © 2020-2023  润新知