cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

This community is for technical, feature, configuration and deployment questions.
For production deployment issues, please contact the TAC! We will not comment or assist with your TAC case in these forums.
Please see How to Ask the Community for Help for other best practices.

988
Views
0
Helpful
1
Replies
Richie20
Beginner

Cisco ISE Internal User with python

Hi Everyone 

I am new to Cisco ISE  with python and  I would like to create ISE Internal User with python script

 

import requests
import json
import argparse
import ssl
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

 

url = "https://192.168.10.18/ers/config/internaluser"

#Input Parameter
parser = argparse.ArgumentParser()
subparser = parser.add_subparsers(dest='command')
login = subparser.add_parser('login')
register = subparser.add_parser('register')
login.add_argument('--name', type=str, required=True)
login.add_argument('--password', type=str, required=True)
register.add_argument('--firstname', type=str, required=True)
register.add_argument('--lastname', type=str, required=True)
register.add_argument('--username', type=str, required=True)
register.add_argument('--email', type=str, required=True)
register.add_argument('--password', type=str, required=True)
register.add_argument('--identityGroups', type=str, required=True)
register.add_argument('--expiryeDate', type=str, required=True)
register.add_argument('--enablePasword', type=str, required=True)

 

args = parser.parse_args()
if args.command == 'login':
print('Logging in with username:', args.username,
'and password:', args.password)
elif args.command == 'register':
print('Creating username', args.username,
'for new member', args.firstname, args.lastname,
'with email:', args.email,
'with identityGroups:', args.identityGroups,
'with expiryDate:', args.identityGroups,
'and enablePassowrd:', args.enablePassword,


{

req_body_json= """ {{

"InternalUser" : {

"id" : "{}",

"name" : "{}",

"description" : "{}",

"enabled" : true,

"email" : "{}",

"password" : "{}",

"firstName" : "{}",

"lastName" : "{}",

"changePassword" : true,

"identityGroups" : "{}",

"expiryDateEnabled" : false,

"expiryDate" : "{}",

"enablePassword" : "{}",

"customAttributes" : {

"key1" : "value1",

"key2" : "value3"

},

"passwordIDStore" : "Internal Users"

}

}
}}
"""S.format(name,description,firstname,lastname,identityGroups,expirydate,enablePassword)
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Basic cmFjb2xhdHNlOm9GbFBScm5lNDU='
}

conn.request("POST", "/ers/config/guestuser/", headers=headers, body=req_body_json)


res = conn.getresponse()
data = res.read()

print("req_body_json")

 

this is my error

File "C:\Users\ghibuser\Desktop\ERSInternalUser.py", line 90
headers = {
^
SyntaxError: invalid syntax

 

Any suggestions are welcome to improve this code  for Cisco ISE to 

1 ACCEPTED SOLUTION

Accepted Solutions
thomas
Cisco Employee

You error has to do with basic Python syntax and not ISE APIs. Consider using a free development environment like Atom, Sublime or VSCode to catch Python syntax issues.

When pasting your code, please use Preformatted text when pasting your code in the community post so we read it.

Screen Shot 2021-05-06 at 12.38.16 PM.png

Python is extremely sensitive to tabs/spaces used for indentation to declare scope.

And it's a lot easier for you and everyone here to catch syntax errors.

The only obvious things I can see is

1) you need to keep the """ on it's own line

"""
S.format(name,description,firstname,lastname,identityGroups,expirydate,enablePassword)

2) you are trying to format the undefined variable S above but the actual string you want to format is req_body_json

 

View solution in original post

1 REPLY 1
thomas
Cisco Employee

You error has to do with basic Python syntax and not ISE APIs. Consider using a free development environment like Atom, Sublime or VSCode to catch Python syntax issues.

When pasting your code, please use Preformatted text when pasting your code in the community post so we read it.

Screen Shot 2021-05-06 at 12.38.16 PM.png

Python is extremely sensitive to tabs/spaces used for indentation to declare scope.

And it's a lot easier for you and everyone here to catch syntax errors.

The only obvious things I can see is

1) you need to keep the """ on it's own line

"""
S.format(name,description,firstname,lastname,identityGroups,expirydate,enablePassword)

2) you are trying to format the undefined variable S above but the actual string you want to format is req_body_json

 

View solution in original post

Create
Recognize Your Peers
Polls
Which of these topics should we host an event in the Community?

Top Choice: ISE Demo (100%)

Content for Community-Ad

ISE Webinars



Did you miss a previous ISE webinar?

CiscoISE YouTube Channel