05-01-2021 02:39 AM
Hi All,
I would like to create internal users using Python script.
my script is attached to this discussion and the error as well
Any help would be welcomed !!
Regards,
Richard
Solved! Go to Solution.
05-01-2021 08:36 AM
Hi @RichardAcolatse8417 ,
first things first ...
Please double check the way you are using the format command, a simple example:
Id = "B100"
req_body_json = """{{
\"InternalUser\": {{
\"id\" : \"{}\"
}}
}}""".format (Id)
print (req_body_json)
result:
{
"InternalUser": {
"id" : "B100"
}
}
Note: special attention to the '{{', '}}' and '\' !!!
Hope this helps !!!
05-01-2021 05:18 AM
as per the information below thread was resolve ? or is this different ?
https://community.cisco.com/t5/network-access-control/cisco-ise-with-python/m-p/4395241#M566955
05-01-2021 05:32 AM
05-01-2021 05:35 AM
Please I need to use the script urgently . Any help would be appreciated
05-01-2021 05:39 AM
the IndexError: list index out of range is probably caused if you are not passing any commandline argument (or few commandline arguments), and thus sys.argv[4] is out of bounds.
For example:
import sys
argv = sys.argv[1]
print ("The name of the script: ", sys.argv[0])
print ("The argument: ", argv)
for: py sysargv.py Hi
The name of the script: sysargv.py
The argument: Hi
for: py sysargv.py
Traceback (most recent call last):
File "sysargv.py", line 2, in <module>
argv = sys.argv[1]
IndexError: list index out of range
Hope this helps !!!
05-01-2021 05:58 AM
Thank you for you help . can you give me any suggestion of how to implement internal user api with python
https://developer.cisco.com/docs/identity-services-engine/3.0/#!internal-user/create
05-01-2021 07:47 AM
Hi @RichardAcolatse8417 ,
let's start with the basics ...
the command would be something like this:
py ISEInternalUserTest.py 192.198.1.1 ers-admin admin20! B100 robert Robert Acolatse Password1 <email> <identityGroups> 12/26/2020
Double check the following in your script:
from
expiryDate = sys.argv[11] # “12/26/2020”
to
identityGroups = sys.argv[10] # “identityGroups”
expiryDate = sys.argv[11] # “12/26/2020”
from
format(Id,name,firstName,lastName,emailAddress,password,identityGroups,expiryDate)
to
format(Id,userName,firstName,lastName,emailAddress,password,identityGroups,expiryDate)
Hope this helps !!!
05-01-2021 08:09 AM
where do I enter this command on windows PC ? can i Write a python script without command line
05-01-2021 08:36 AM
Hi @RichardAcolatse8417 ,
first things first ...
Please double check the way you are using the format command, a simple example:
Id = "B100"
req_body_json = """{{
\"InternalUser\": {{
\"id\" : \"{}\"
}}
}}""".format (Id)
print (req_body_json)
result:
{
"InternalUser": {
"id" : "B100"
}
}
Note: special attention to the '{{', '}}' and '\' !!!
Hope this helps !!!
05-01-2021 09:13 AM
05-01-2021 01:04 PM
Hi @RichardAcolatse8417 ,
double check your ISE Internal User(4).py script ... for example:
emailAddress = sys.argv[9] # "rmensah@cisco.com
expiryDate = sys.argv[11] # “12/26/2020”
where is sys.argv[10]?
The ISE Internal Users(2).py script looks better ... have you test it?
Regards
05-01-2021 02:15 PM - edited 05-01-2021 02:19 PM
05-02-2021 04:34 AM
05-02-2021 05:28 AM - edited 05-03-2021 03:24 AM
#!/usr/bin/python
import http.client
import base64
import ssl
import sys
import os
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] # "Acolatse"
password = sys.argv[8] # "Password1"
emailAddress = sys.argv[9] # "rmensah@cisco.com
expiryDate = sys.argv[11] # “12/26/2020”
identityGroups = sys.argv[10] # “identityGroups”
# 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(Id,UserNname,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_req_json)
I got this error while run by script
Traceback (most recent call last):
File "C:\Users\ghibuser\Desktop\ISEInternalUserTest.py", line 38, in <module>
req_body_json = """{{
IndexError: Replacement index 7 out of range for positional args tuple
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide