0

I'm trying to parse a list of IP:ports via a command argument to variable called HOSTS, to be used in a function - read_head_block_ints.

parser = argparse.ArgumentParser(description='chain info checker')
parser.add_argument('host', help='host address')
parser.add_argument('function', help='check to run', choices=ALLOWED_FUNCTIONS)
parser.add_argument('--hosts', dest='HOSTS', type=list)

def read_head_block_ints():
    for host in HOSTS:
        try:
            data = requests.get(URLS['get_info'].format(host=host), verify=False).json()  # returns data in JSON format
            HEAD_BLOCK_INTS.append(float(data['head_block_num']))   # this is the head_block INT
        except:
            print('Error cannot connect to host {host}'.format(host=host))

When I call the script using --hosts 1.2.3.4:888 5.6.7.8:8888 9.9.9.9:8888

I get the following error: unrecognized arguments: 5.6.7.8:8888 9.9.9.9:8888

Ankh2054
  • 1,103
  • 2
  • 16
  • 39

1 Answers1

0
parser = argparse.ArgumentParser(description='chain info checker')
parser.add_argument('host', help='host address')
parser.add_argument('function', help='check to run', choices=ALLOWED_FUNCTIONS)
parser.add_argument('--hosts', dest='HOSTS', type=list)

def read_head_block_ints():
    for host in HOSTS:
        try:
            data = requests.get(URLS['get_info'].format(host=host), verify=True).json()  # returns data in JSON format
            HEAD_BLOCK_INTS.append(float(data['head_block_num']))   # this is the head_block INT 
        except:
            print('Error cannot connect to host {host}'.format(host=host))

put verify as True

Stephan202
  • 59,965
  • 13
  • 127
  • 133