|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 wnhuiyou 于 2022-4-23 13:16 编辑
代码:
报错:
整个代码:
- # #!/usr/bin/env python
- # # -*- encoding:utf8 -*-
- import requests
- import json
- import sys
- requests.packages.urllib3.disable_warnings()
- class ArubaAPI:
- # 初始化节点登录信息
- def __init__(self, host, user, password, command, port=4343):
- self.login_url = 'https://{}:{}/v1/api/login'.format(host, port)
- self.command_url = 'https://{}:{}/v1/configuration/showcommand'.format(host, port)
- self.username = user
- self.password = password
- self.port = port
- self.command = command
- self.request_header = {'User-Agent': 'Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) '
- 'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/67.0.3396.87 '
- 'Mobile Safari/537.36'}
- def main(self):
- # 保持会话
- r = requests.session()
- try:
- # 登录节点,获取UIDARUBA
- # 登录节点
- params = {'username': self.username, 'password': self.password}
- response = r.get(url=self.login_url, params=params, verify=False)
- # 获取UIDARUBA
- # print(response.text)
- UIDARUBA = json.loads(response.text).values()[0].get("UIDARUBA")
- # print(UIDARUBA)
- # 执行命令
- params = {'UIDARUBA': str(UIDARUBA), "command": self.command}
- # print(params)
- response = r.get(url=self.command_url, params=params, verify=False, headers=self.request_header)
- # print(response.text)
- # except Exception as e:
- # print(e) #访问异常,try内容异常
- except:
- print("-5") # 访问异常,try内容异常
- # 在线设备
- User_Client_list = json.loads(response.text).get("Users")
- print(len(User_Client_list))
- # AP清单,列表
- # 列表里记录着AP状态信息,字典
- # AP_list = json.loads(response.text).get("AP Database")
- # print(AP_list)
- # 循环列表元素,判断字典中Status状态值
- # Down_AP = []
- # for ap in AP_list:
- # AP_Status = ap.get("Status")
- # if AP_Status == "Down":
- # Down_AP.append("离线AP:" + str(ap.get("Name")))
- # for ap in Down_AP:
- # print(ap)
- if __name__ == '__main__':
- login = ArubaAPI('host', 'user', 'passw', 'show user-table')
- login.main()
复制代码
请教下各位,需要怎么修改呢? |
|