cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2414
Views
0
Helpful
2
Replies

Create Internal Users with python

Richie20
Level 1
Level 1

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
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
Level 1
Level 1

Any suggestions are welcomed

thomas
Cisco Employee
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.