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.

1061
Views
0
Helpful
2
Replies
Richie20
Beginner

Create Internal Users with python

Hi Everyone ,

I am  creating internal user with python and argparse

This is error with my command 

C:\Users\guser\Desktop>python user1.py abt200 john.doe@gh.co.uk pa@ssWord1 John Doe
Traceback (most recent call last):
File "C:\Users\guser\Desktop\user1.py", line 24, in <module>
req_body_json = """ {{
IndexError: Replacement index 5 out of range for positional args tuple

 

this is my code :

#!/usr/bin/env python
import requests
import json
import argparse
import sys

requests.packages.urllib3.disable_warnings()


url = "https://192.169.35.16:9060/ers/config/internaluser"

parser = argparse.ArgumentParser()

parser.add_argument("name", help='Enter the name')
parser.add_argument("email", help='Enter the email')
parser.add_argument("password", help='Enter the password')
parser.add_argument("firstname", help='Enter the first name')
parser.add_argument("lastname", help='Enter the last name')

opts = parser.parse_args()

 

req_body_json = """ {{
"InternalUser" : {{
"name" : "{}",
"enabled" : true,
"email" : "{}",
"password" : "{}",
"firstName" : "{}",
"lastName" : "{}",
"changePassword" : true,
"expiryDateEnabled" : true,
"expiryDate" : "{}",
"enablePassword" : "{}",
"customAttributes" : {{
}},
"passwordIDStore" : "Internal Users"
}}
}}
""".format("name","email","passorwd","firstname","lastname")

headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Basic ZXJzYWRtaW46b0ZsUFJybmU0NTE=',
'Cookie': 'APPSESSIONID=A70D7085616DB14AD231971CA4A83803; Cookie_1=value; JSESSIONIDSSO=B37E2D40D9E08A8CE005198A09FC247F'
}

response = requests.request("POST", url, headers=headers, body=req_body_json, verify=False)


#print the namespace object
#print (opts)
print(response.text)
print ('The name is' + opts.name)
print ('The email is ' + opts.email)
print ('The password is' + opts.password)
print ('The first name is' + opts.firstname)
print ('The last name is ' + opts.lastname)
print(req_body_json)

 

 

Any Help would  appreciated 

Thank you ,

Richie

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
thomas
Cisco Employee

See my response to @Richie20 in the post Creating Internal users by python and argparse

 

I think @Richie20 and @RichardAcolatse8417 are the same person - you both ask very similar questions at nearly the same time on the same day and have identical "Any suggestions are welcomed" followup requests.

 

Please don't duplicate requests.

View solution in original post

2 REPLIES 2
Richie20
Beginner

Any suggestions are welcomed

thomas
Cisco Employee

See my response to @Richie20 in the post Creating Internal users by python and argparse

 

I think @Richie20 and @RichardAcolatse8417 are the same person - you both ask very similar questions at nearly the same time on the same day and have identical "Any suggestions are welcomed" followup requests.

 

Please don't duplicate requests.

View solution in original post

Create
Recognize Your Peers
Content for Community-Ad

ISE Webinars



Did you miss a previous ISE webinar?

CiscoISE YouTube Channel