05-05-2021 08:59 AM - edited 05-05-2021 09:52 AM
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
Solved! Go to Solution.
05-06-2021 12:47 PM - edited 05-06-2021 12:48 PM
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.
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
05-06-2021 12:47 PM - edited 05-06-2021 12:48 PM
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.
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
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