import json import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning # disable certificate warnings requests.packages.urllib3.disable_warnings(InsecureRequestWarning) hostname = "ise.securitydemo.net" username = "admin" password = "C1sco12345" resource = "internaluser" internaluser_template = """ {{ "InternalUser" : {{ "name" : "{name}", "firstName" : "{firstName}", "lastName" : "{lastName}", "email" : "{email}", "password" : "{password}" }} }} """ data = internaluser_template.format( name="isabt202", firstName="John", lastName="Brown", email="john.Brown@contoso.com", password="1spa@ssWord" ) url = f"https://{hostname}:9060/ers/config/{resource}" response = requests.post( url, auth=(username, password), headers={"Accept": "application/json", "Content-Type": "application/json"}, data=data, verify=False, ) # Show request headers and body print(f"-" * 80) sorted_headers = sorted(response.request.headers.items()) for key, value in sorted_headers: print(f"{key}:[{value}]") print(f"data:{data}") # Show response headers print(f"-" * 80) sorted_headers = sorted(response.headers.items()) for key, value in sorted_headers: print(f"{key}:[{value}]") # show URL of new resource or failure reason print(f"-" * 80) if response.ok: print(f'{resource} : {response.headers["Location"]}') else: print(f"{response.status_code} : {response.content.decode()}")