I have a piece of code like below which is used to send a list of IP addresses to an API call.
body = {'cID': id, 'dbType': params['db-type'].upper(), 'cidrList': eval(params['--cidr-list'])}
print(json.dumps(body))
conn.request("POST", "/Link/to/API", body=json.dumps(body), headers=header)
check_resp(200)
logger.info("Rules changed successfully")
However, when I call this code using the below params, it fails.
--cidr-list ['10.20.0.0/32','10.30.0.0/32']
It works when I use the below.
--cidr-list [\"10.20.0.0/32\",\"10.30.0.0/32\"]
So basically when I use \"
to wrap each item of the list, it is parsed as single quotes. How do I change the code so that it accepts input 1? I'm new to Python and I would appreciate if you could explain the logic behind it as well. Thanks in advance.