<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating Internal users by python and argparse in Network Access Control</title>
    <link>https://community.cisco.com/t5/network-access-control/creating-internal-users-by-python-and-argparse/m-p/4408247#M567538</link>
    <description>&lt;P&gt;Any suggestions are welcomed&lt;/P&gt;</description>
    <pubDate>Tue, 25 May 2021 12:00:01 GMT</pubDate>
    <dc:creator>RichardAcolatse8417</dc:creator>
    <dc:date>2021-05-25T12:00:01Z</dc:date>
    <item>
      <title>Creating Internal users by python and argparse</title>
      <link>https://community.cisco.com/t5/network-access-control/creating-internal-users-by-python-and-argparse/m-p/4407676#M567505</link>
      <description>&lt;P&gt;Hi All ,&lt;/P&gt;&lt;P&gt;I creating a python script with python and Json with argparse . i encouter an error with while run the command with my script&lt;/P&gt;&lt;P&gt;. Below is the command with the error&lt;/P&gt;&lt;P&gt;:\Users\user\Desktop&amp;gt;python user2.py abt200 john.doe@contos pa@ssWord John Brown&lt;BR /&gt;The name isabt200&lt;BR /&gt;The email is john.Brown@contoso.com&lt;BR /&gt;The password ispa@ssWord&lt;BR /&gt;The first name isJohn&lt;BR /&gt;The last name is Brown&lt;BR /&gt;{&lt;BR /&gt;"ERSResponse" : {&lt;BR /&gt;"operation" : "POST-create-internaluser",&lt;BR /&gt;"messages" : [ {&lt;BR /&gt;"title" : "Invalid JSON Input: No content to map to Object due to end of input",&lt;BR /&gt;"type" : "ERROR",&lt;BR /&gt;"code" : "Application resource validation exception"&lt;BR /&gt;} ],&lt;BR /&gt;"link" : {&lt;BR /&gt;"rel" : "related",&lt;BR /&gt;"href" : "&lt;A href="https://192.169.49.15:9060/ers/config/internaluser" target="_blank"&gt;https://192.169.49.15:9060/ers/config/internaluser&lt;/A&gt;",&lt;BR /&gt;"type" : "application/xml"&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions are welcome&lt;/P&gt;&lt;P&gt;kind Regards&lt;/P&gt;</description>
      <pubDate>Mon, 24 May 2021 14:00:47 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-access-control/creating-internal-users-by-python-and-argparse/m-p/4407676#M567505</guid>
      <dc:creator>RichardAcolatse8417</dc:creator>
      <dc:date>2021-05-24T14:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Internal users by python and argparse</title>
      <link>https://community.cisco.com/t5/network-access-control/creating-internal-users-by-python-and-argparse/m-p/4407677#M567506</link>
      <description>&lt;P&gt;This is my code&amp;nbsp; as well&lt;/P&gt;&lt;P&gt;#!/usr/bin/env python&lt;BR /&gt;import argparse&lt;BR /&gt;import requests&lt;BR /&gt;import json&lt;/P&gt;&lt;P&gt;requests.packages.urllib3.disable_warnings()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;url = "&lt;A href="https://192.168.30.13:9060/ers/config/internaluser" target="_blank" rel="noopener"&gt;https://192.169.49.15:9060/ers/config/internaluser&lt;/A&gt;"&lt;BR /&gt;parser = argparse.ArgumentParser()&lt;/P&gt;&lt;P&gt;#positional arguments&lt;BR /&gt;parser.add_argument('name', help='Enter the name')&lt;BR /&gt;parser.add_argument('email', help='Enter the email')&lt;BR /&gt;parser.add_argument('password', help='Enter the password')&lt;BR /&gt;parser.add_argument('firstname', help='Enter the first name')&lt;BR /&gt;parser.add_argument('lastname', help='Enter the last name')&lt;/P&gt;&lt;P&gt;opts = parser.parse_args()&lt;/P&gt;&lt;P&gt;#print the namespace object&lt;BR /&gt;#print (opts)&lt;/P&gt;&lt;P&gt;print ('The name is' + opts.name)&lt;BR /&gt;print ('The email is ' + opts.email)&lt;BR /&gt;print ('The password is' + opts.password)&lt;BR /&gt;print ('The first name is' + opts.firstname)&lt;BR /&gt;print ('The last name is ' + opts.lastname)&lt;/P&gt;&lt;P&gt;payload ={}&lt;BR /&gt;headers = {&lt;BR /&gt;'Content-Type': 'application/json',&lt;BR /&gt;'Accept': 'application/json',&lt;BR /&gt;'Authorization': 'Basic ZXJzYWRtaW46b0ZsUFJybmU0NTE=',&lt;BR /&gt;'Cookie': 'APPSESSIONID=A70D7085616DB14AD231971CA4A83803; Cookie_1=value; JSESSIONIDSSO=B37E2D40D9E08A8CE005198A09FC247F'&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;response = requests.request("POST", url, headers=headers, data=payload, verify=False)&lt;/P&gt;&lt;P&gt;print(response.text)&lt;/P&gt;</description>
      <pubDate>Mon, 24 May 2021 14:02:26 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-access-control/creating-internal-users-by-python-and-argparse/m-p/4407677#M567506</guid>
      <dc:creator>RichardAcolatse8417</dc:creator>
      <dc:date>2021-05-24T14:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Internal users by python and argparse</title>
      <link>https://community.cisco.com/t5/network-access-control/creating-internal-users-by-python-and-argparse/m-p/4408247#M567538</link>
      <description>&lt;P&gt;Any suggestions are welcomed&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 12:00:01 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-access-control/creating-internal-users-by-python-and-argparse/m-p/4408247#M567538</guid>
      <dc:creator>RichardAcolatse8417</dc:creator>
      <dc:date>2021-05-25T12:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Internal users by python and argparse</title>
      <link>https://community.cisco.com/t5/network-access-control/creating-internal-users-by-python-and-argparse/m-p/4413727#M567721</link>
      <description>&lt;P&gt;I highly recommend learning some Python basics - you have a JSON error because your JSON payload is &lt;STRONG&gt;empty&lt;/STRONG&gt;:&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;{}&lt;/FONT&gt; &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://developer.cisco.com/learning/modules" target="_blank"&gt;https://developer.cisco.com/learning/modules&lt;/A&gt; has a &lt;A href="https://developer.cisco.com/learning/modules/programming-fundamentals" target="_self"&gt;&lt;STRONG&gt;Programming Fundamentals&lt;/STRONG&gt;&lt;/A&gt; course that can help you learn&amp;nbsp; Python and JSON. You need to dump/print the output of your JSON payload before sending it to ISE. This is basic software troubleshooting. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have created some scripts for you that do what you want (without &lt;FONT face="courier new,courier"&gt;argparse&lt;/FONT&gt;) and I successfully tested them on my ISE node.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;ise_get_simple_internaluser.txt&lt;/FONT&gt;: dumps an &lt;FONT face="courier new,courier"&gt;internaluser&lt;/FONT&gt; request. Modify it for other resources.&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;ise_post_simple_internaluser.txt&lt;/FONT&gt; : uses an static JSON data string.&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;ise_post_simple_internaluser_template.txt&lt;/FONT&gt; : uses a template to substitute values into the JSON data. You can modify this with values from &lt;FONT face="courier new,courier"&gt;argparse&lt;/FONT&gt;.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I had to remove the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;#!/usr/bin/env python3&lt;/FONT&gt; "shebang" line from the top of each file and change the file extension from &lt;FONT face="courier new,courier"&gt;.py&lt;/FONT&gt; to &lt;FONT face="courier new,courier"&gt;.txt&lt;/FONT&gt; extension to attach the files to this community page - change it before running them! I also had to slightly change your password to be allowed with the default ISE password policy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They all dump the headers, data, and response values so I can verify what I am sending and what is coming back. This is the kind of troubleshooting with &lt;FONT face="courier new,courier"&gt;print&lt;/FONT&gt; statements that you need when you are beginning to do REST programming with Python or any language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the output of one of the scripts so you can easily see what it is sending and receiving :&lt;/P&gt;
&lt;PRE&gt;./ise_post_simple_internaluser.py&lt;BR /&gt;--------------------------------------------------------------------------------&lt;BR /&gt;Accept:[application/json]&lt;BR /&gt;Accept-Encoding:[gzip, deflate]&lt;BR /&gt;Authorization:[Basic YWRtaW46QzFzY28xMjM0NQ==]&lt;BR /&gt;Connection:[keep-alive]&lt;BR /&gt;Content-Length:[200]&lt;BR /&gt;Content-Type:[application/json]&lt;BR /&gt;User-Agent:[python-requests/2.25.1]&lt;BR /&gt;data:&lt;BR /&gt;{&lt;BR /&gt;    "InternalUser": {&lt;BR /&gt;        "name": "isabt200",&lt;BR /&gt;        "firstName" : "John",&lt;BR /&gt;        "lastName" : "Brown",&lt;BR /&gt;        "email" : "john.Brown@contoso.com",&lt;BR /&gt;        "password" : "1spa@ssWord"&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;--------------------------------------------------------------------------------&lt;BR /&gt;Cache-Control:[no-cache, no-store, must-revalidate]&lt;BR /&gt;Connection:[keep-alive]&lt;BR /&gt;Content-Length:[0]&lt;BR /&gt;Content-Security-Policy:[default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:;]&lt;BR /&gt;Content-Type:[application/json;charset=utf-8]&lt;BR /&gt;Date:[Sun, 06 Jun 2021 22:20:37 GMT]&lt;BR /&gt;Expires:[Thu, 01 Jan 1970 00:00:00 GMT]&lt;BR /&gt;Keep-Alive:[timeout=60]&lt;BR /&gt;Location:[https://ise.securitydemo.net:9060/ers/config/internaluser/33226f95-3694-4dd0-9c0d-53302ba906f8]&lt;BR /&gt;Pragma:[no-cache]&lt;BR /&gt;Server:[]&lt;BR /&gt;Set-Cookie:[JSESSIONIDSSO=91997FD281ABEFB04973D93734B1FB21; Path=/; Secure; HttpOnly, APPSESSIONID=44DCE40B329012621CCF6038EFDB4ED1; Path=/ers; Secure; HttpOnly]&lt;BR /&gt;Strict-Transport-Security:[max-age=31536000; includeSubDomains]&lt;BR /&gt;X-Content-Security-Policy:[default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:;]&lt;BR /&gt;X-Content-Type-Options:[nosniff]&lt;BR /&gt;X-Frame-Options:[SAMEORIGIN]&lt;BR /&gt;X-WebKit-CSP:[default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:;]&lt;BR /&gt;X-XSS-Protection:[1; mode=block]&lt;BR /&gt;--------------------------------------------------------------------------------&lt;BR /&gt;internaluser : https://ise.securitydemo.net:9060/ers/config/internaluser/33226f95-3694-4dd0-9c0d-53302ba906f8&lt;/PRE&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jun 2021 23:03:49 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-access-control/creating-internal-users-by-python-and-argparse/m-p/4413727#M567721</guid>
      <dc:creator>thomas</dc:creator>
      <dc:date>2021-06-06T23:03:49Z</dc:date>
    </item>
  </channel>
</rss>

