import requests
class Test:
def __init__(self):
'''用来保持会话'''
self.session = requests.Session() #导入requests库的Session类(类是大写)
self.uuid = {}
def get_code(self):
'''封装获取code码的接口'''
get_code_url = 'http://manage.duoceshi.com/auth/code'
get_code_headers = {'Content-Type': 'application/x-www-form-urlencoded'}
response = self.session.get(url=get_code_url,headers=get_code_headers)
result = response.json()
self.uuid["uuid"] = result["uuid"] #把最新的uuid构造函数里面
def login(self):
"""封装一个登录接口"""
login_url = "http://manage.duoceshi.com/auth/login"
login_headers = {'Content-Type': 'application/json'}
login_data = {
"username": "admin",
"password": "ZLr4Wka9fPR2WLCWuR5pERmymJYTpDomTkd7VqidZNzGa/NFOd34xjEqLJ2Z3uze4BWN0kFXcVOQ6x6+4inwkQ==",
"code": "8888",
"uuid": self.uuid["uuid"]
}
response = self.session.post(url=login_url, json=login_data, headers=login_headers)
print(response.json())
if __name__ == '__main__':
t = Test()
t.get_code()
t.login()
05-24
1121
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)