#!/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