cancelar
Mostrando los resultados de 
Buscar en lugar de 
Quiere decir: 
cancel
4350
Visitas
20
ÚTIL
13
Respuestas

ISE Internal user creation using Python script

ISE Internal user using Python script

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

 

1 SOLUCIÓN ACEPTADA

Soluciones aceptadas

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 !!!

Ver la solución en mensaje original publicado

13 RESPUESTAS 13

balaji.bandi
Hall of Fame
Hall of Fame

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

BB

=====Preenayamo Vasudevam=====

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

it was not  resolved . it is possible you can can show me how to create internal user with the script you suggested to me  ? i am struggle to execute the python script . I need to use it  urgently 

Please I  need  to use the script urgently . Any help would be appreciated  

Hi @RichardAcolatse8417 

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 !!!

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

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 !!!

where do I enter  this command  on windows PC ? can i Write  a python  script without  command line 

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 !!!

Can you check if it is correct or wrong   ? can i also implement this way too 

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

Like this

#!/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