import requests
import unittest
import json
class scm_api(unittest.TestCase):
def test_get_paramete(self):
url='http://XXXXXXXuser/login'
data={
"account":"XXXX",
"password":"XXXXX"
}
session=requests.session()#保持状态
session.post(url, json=data)
# url_text=session.post(url,json=data)
# print(json.dumps(url_text.json(),indent=4,ensure_ascii=False,sort_keys=True))
# Token=url_text.json()['data']['token']
# Token={'token':Token}
# return Token
url_1='http://XXXXXXX/topAddrs'
url_text_1=session.get(url_1)
print(json.dumps(url_text_1.json(),indent=4,ensure_ascii=False,sort_keys=True))
if __name__=='__main__':
unittest.main()
1、requests.Session()可以在会话中保留状态,保持cookie等;如上实例就不用再传入cookie参数