Hello All,
When I run the below script, I get this error...
print ('{}|{}|{}'.format(x['hostname'], x ['vlanid'], x['vlandescription']))
TypeError: string indices must be integers
...here is my script...
Any advice?
When I run the below script, I get this error...
print ('{}|{}|{}'.format(x['hostname'], x ['vlanid'], x['vlandescription']))
TypeError: string indices must be integers
...here is my script...
import sys import requests,urllib3,json,pprint urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) def get_vlanid (): response = raw_input("Please Enter VLAN ID:") url = 'https://<URL>:8443/nds/vlanDB/vlantool/vlanid/' body = '[{"vlanid": "%s"}]' % response s = requests.session() req = s.post(url, headers={'apikey': '<API_KEY>','Accept': 'application/json', 'Content-type': 'application/json'}, verify=False, data=body) result = json.loads(req.content) for x in result: print ('{}|{}|{}'.format(x['hostname'], x ['vlanid'], x['vlandescription'])) #get_all() get_vlanid ()I think on the json I'm pulling from is identifying the vlanid, as an integer? And, I need to tell the print command to expect such?
Any advice?