05-03-2021 06:56 AM - edited 05-03-2021 07:22 AM
Hi everyone
Any urgent help to fix this error on my code
Traceback (most recent call last):
File "C:\Users\ghibuser\Desktop\ISEInternalUserTest.py", line 25, in <module>
identityGroups = sys.argv[11] # “Employee”
IndexError: list index out of range
This is my code
#!/usr/bin/python
import http.client
import base64
import ssl
import sys
import os
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
argv = sys.argv[1]
print ("The name of the script: ", sys.argv[0])
print ("The argument are: ", argv)
#parameters
id = sys.argv[4] # "B100"
userName = sys.argv[5] # "robert"
firstName = sys.argv[6] # "Robert"
lastName = sys.argv[7] # " Mensah"
password = sys.argv[8] # "Password1"
emailAddress = sys.argv[9] # "rmensah@gh.com
expiryDate = sys.argv[10] # “12/26/2022”
identityGroups = sys.argv[11] # “Employee”
# host and authentication credentials
host = sys.argv[1] # "192.198.1.1"
user = sys.argv[2] # “ers.admin”
password = sys.argv[3] # “admin20!”
conn = http.client.HTTPSConnection("{}:9060".format(host), context=ssl.SSLContext(ssl.PROTOCOL_TLS))
creds = str.encode(':'.join((user, password)))
encodedAuth = bytes.decode(base64.b64encode(creds))
req_body_json = """{{
\"InternalUser\" : {{
\"id"\ : "\{}\",
\"userName\" : "\{}\",
\"description"\ : "\{}\",
"enabled" : true,
\"email\" : "\{}\",
\"password\" : "\{}\",
\"firstName\" : "\{}\",
\"lastName\" : "\{}\",
\"changePassword\" : true,
\"identityGroups\" : "\{}\",
"expiryDateEnabled" : false,
"expiryDate" : "\{}\",
"enablePassword" : "enablePassword",
"customAttributes" : {
"key1" : "value1",
"key2" : "value3"
},
"passwordIDStore" : "Internal Users"
}
}}
}}""".format(userName,firstName,lastName,emailAddress,password,identityGroups,expiryDate)
headers = {
'accept': "application/json",
'content-type': "application/json",
'authorization': " ".join(("Basic",encodedAuth)),
'cache-control': "no-cache",
}
conn.request("POST", "/ers/config/internaluser/", headers=headers, body=req_body_json)
es = conn.getresponse()
data = res.read()
print("Status: {}".format(res.status))
print("Header:\n{}".format(res.headers))
print("Body:\n{}".format(data.decode("utf-8")))
print(req_body_json)
Any help is welcomed
05-03-2021 07:07 AM
Hey @RichardAcolatse8417 ,
looks like you are not supplying enough arguments when running the script.
Could you share your CLI command to run the script?
BR
Rick
05-03-2021 07:23 AM
This is my command line for creating Internal user on ISE
python ISEInternalUserTest.py 192.198.1.1 ers-admin admin20! robert Robert Mensah Password1 rmensah@gha.com Employee 12/26/2020
Thank you
Richard
05-03-2021 07:31 AM
Looks like you are missing the
id = sys.argv[4] # "B100"
command line argument and therefore you only have 10 arguments instead of 11 which means the code
identityGroups = sys.argv[11] # “Employee”
will fail.
BR
Rick
05-03-2021 07:38 AM
how do I solve it to run the command line with Cisco ISE
05-03-2021 07:49 AM
I am getting this error after run this command again
IndexError: Replacement index 8 out of range for positional args tuple
05-03-2021 09:08 AM
Any urgent help to fix the my problem
Thank you
Richard
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: