python验证魔方云api接口token失效时重新生成
时间:2022-10-16 来源:未知 投稿:admin 点击:次
例:
import requests def create_token(): url = 'http://10.30.100.8/sysadmin123/v1/login' data = { 'username': 'fwqzx', 'password': '12345678' } login_res = requests.post(url,json=data) token = login_res.json() f = open('token.txt',mode='w+') f.write(str(token)) f.close() print("token:",token) f = open("token.txt") token = f.read() f.close() print(token) headers = { 'User-Agent': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Connection': 'keep-alive', 'access-token': token } testurl = "http://10.30.100.8/sysadmin123/v1/areas" r = requests.get(testurl,headers=headers) print(r.status_code) print(r) if r.status_code != 200: print("登录失效") print(r.status_code) create_token() print("重新获取token") else: print("登陆成功") print(r.status_code)
如果您的问题仍未解决,还可以加入服务器在线技术交流QQ群:8017413寻求帮助。
相关内容