05-24-2021 05:50 AM
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
Solved! Go to Solution.
06-06-2021 04:10 PM
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.
05-25-2021 04:55 AM - edited 05-25-2021 04:55 AM
Any suggestions are welcomed
06-06-2021 04:10 PM
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.
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