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

Internal User Creation with python script

Hi Everyone ,

I am creating python script for Internal user for Cisco ISE  .  I want to  know if the code format is okay to run the code 

.  Any help of how to run with command line  or python interpreter  

 

#!/usr/bin/python
import requests
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)


url = "xxxxxxxxxxxxxxxxx/ers/config/internaluser"


payload={}
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Cookie': 'APPSESSIONID=B084095F5B5131E3901583FBE99C2129'
}

resources =[]

while (url) :
# add resources to list
response = requests.request("POST", url, headers=headers, data=payload, verify=False)
resources += response.json()["SearchResult"]["resources"]
try :
url = response.json()["SearchResult"]["nextPage"]["href"]
except Exception as e :
url = None

req_body_json = """{{

\"InternalUser\" : {{

\"id"\ : "\{}\",

\"Name\" : "\{}\",


\"description"\ : "\{}\",

"enabled" : true,

\"email\" : "\{}\",

\"password\" : "\{}\",

\"firstName\" : "\{}\",

\"lastName\" : "\{}\",

\"changePassword\" : true,

\"identityGroups\" : "\{}\",

"expiryDateEnabled" : false,

"expiryDate" : "\{}\",

"enablePassword" : "enablePassword",

"customAttributes" : {

"key1" : "value1",

"key2" : "value3"

},

"passwordIDStore" : "Internal Users"

}
}}
}}""".format(id,userName,firstName,lastName,emailAddress,password,identityGroups,expiryDate)

print(req_body_json)

 

Can any one help me out with this error . i need help urgently 

Traceback (most recent call last):
File "C:/Users/ghibuser/Desktop/internal_user.py", line 22, in <module>
response = requests.request("POST", url, headers=headers, data=payload, verify=False)
File "C:\Users\ghibuser\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\ghibuser\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 528, in request
prep = self.prepare_request(req)
File "C:\Users\ghibuser\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 456, in prepare_request
p.prepare(
File "C:\Users\ghibuser\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 316, in prepare
self.prepare_url(url, params)
File "C:\Users\ghibuser\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 390, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'xxxxxxxxxxxxxxxxx/ers/config/internal

 

 

 

2 Replies 2

Timothy Abbott
Cisco Employee
Cisco Employee

Hi,

 

You will have to consult python documentation for code formatting.  Maybe someone in the community with python experience will be able to comment.

 

Regards,

Tim

Thank you for your assistance