May-02-2023, 12:00 AM
(This post was last modified: May-02-2023, 12:00 AM by billykid999.)
I tried to define the sys.argv within the class itself, and I still get TypeError 'str' object is not callable.
and it's giving me the TypeError 'str' object is not callable
whether or not I pass in a list for sys.argv[0] in the command line.
however when I change inlist to:
and now it is working fine. I don't want to be able to do this by passing in a list in the CLI...
I tried
import sys import netmiko import json from Hardware_info import HardwareMaintenance Hardware = HardwareMaintenance.hardware_handler class Connect: def __init__(self, **kwargs): # self.protocol = netmiko.ssh_autodetect # pass intake_file = open('ip_list.txt', 'r') self.json_data = [json.loads(line) for line in intake_file] self.kwargs = [Hardware] def connect_parser(self, inlist=[]): inlist = sys.argv[0] for data in self.json_data: ip = data["ip"] # port = data["port"] username = data["username"] if data["username"] else "" password = data["password"] if data["password"] else "" secret = data["secret"] if "secret" in data else False device_type = data["device_type"] if data["device_type"] else "" if data["header"] == "Netmiko": print("The variables being passed: " + ip, username, password, device_type) ConnectHandler = netmiko.ConnectHandler( device_type=device_type, host=ip, username=username, password=password, port=22, secret=data["secret"] if "secret" in data else False ) ConnectHandler.enable() for i in inlist: i(ConnectHandler,ip) if __name__ == "__main__": from Connect_Handler import Hardware from Connect_Handler import Connect print(Connect().connect_parser()) inlist = sys.argv[0] #Connector.Connect(inlist) # def runner(): # #for i in sys.argv[0]: # Hardware(Connector.) # runner()notice I added
for i in inlist: i(ConnectHandler,ip)to the end under ConnectHandler.enable()
and it's giving me the TypeError 'str' object is not callable
whether or not I pass in a list for sys.argv[0] in the command line.
however when I change inlist to:
def connect_parser(self, inlist=[]): inlist = [Hardware]notice i included Hardware
and now it is working fine. I don't want to be able to do this by passing in a list in the CLI...
I tried
def connect_parser(self, inlist=[]): inlist = sys.argv[0]and no go