Hi, i have some problems adding users to my organization in portal 10.5.1, i found this python code to add users using the portal web service /portaladmin/security/users/createUser:
<SPAN class="comment token">#!/usr/bin/env python</SPAN>
<SPAN class="comment token"># Requires Python 2.7+</SPAN>
<SPAN class="comment token"># Demonstrates how to add users to Portal for ArcGIS in bulk</SPAN>
<SPAN class="comment token"># For Http calls</SPAN>
<SPAN class="keyword token">import</SPAN> httplib<SPAN class="punctuation token">,</SPAN> urllib2<SPAN class="punctuation token">,</SPAN> urllib<SPAN class="punctuation token">,</SPAN> json
<SPAN class="comment token"># For system tools</SPAN>
<SPAN class="keyword token">import</SPAN> sys<SPAN class="punctuation token">,</SPAN> os
<SPAN class="comment token"># For reading passwords without echoing</SPAN>
<SPAN class="keyword token">import</SPAN> getpass
<SPAN class="comment token"># Other utilities</SPAN>
<SPAN class="keyword token">import</SPAN> Queue
<SPAN class="comment token"># Defines the entry point into the script</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">main</SPAN><SPAN class="punctuation token">(</SPAN>argv<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"This script adds users in bulk into a portal. \n"</SPAN>
<SPAN class="comment token">#Get parameters</SPAN>
parameters <SPAN class="operator token">=</SPAN> getParametersFromUser <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
portalURL <SPAN class="operator token">=</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'portalURL'</SPAN><SPAN class="punctuation token">]</SPAN>
provider <SPAN class="operator token">=</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'provider'</SPAN><SPAN class="punctuation token">]</SPAN>
userName <SPAN class="operator token">=</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'userName'</SPAN><SPAN class="punctuation token">]</SPAN>
password <SPAN class="operator token">=</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'password'</SPAN><SPAN class="punctuation token">]</SPAN>
inUserFile <SPAN class="operator token">=</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'inUserFile'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#Get user data from file</SPAN>
usersData <SPAN class="operator token">=</SPAN> getUserDataFromFile<SPAN class="punctuation token">(</SPAN>inUserFile<SPAN class="punctuation token">,</SPAN>provider<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Create users</SPAN>
createUsers <SPAN class="punctuation token">(</SPAN>userName<SPAN class="punctuation token">,</SPAN>password<SPAN class="punctuation token">,</SPAN> portalURL<SPAN class="punctuation token">,</SPAN>provider<SPAN class="punctuation token">,</SPAN> usersData<SPAN class="punctuation token">)</SPAN>
raw_input<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Press ENTER to close the script.'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN>
<SPAN class="comment token"># This function loads all the user data in the input text file into a Python Queue.</SPAN>
<SPAN class="comment token"># This usersQueue can be later passed to the createUsers function</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">getUserDataFromFile</SPAN><SPAN class="punctuation token">(</SPAN>inUserFile<SPAN class="punctuation token">,</SPAN>provider<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
usersQ <SPAN class="operator token">=</SPAN> Queue<SPAN class="punctuation token">.</SPAN>Queue<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
keyParams <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'username'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'password'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'email'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'fullname'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'role'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'description'</SPAN><SPAN class="punctuation token">]</SPAN>
inFileHandle <SPAN class="operator token">=</SPAN> open<SPAN class="punctuation token">(</SPAN>inUserFile<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'r'</SPAN><SPAN class="punctuation token">)</SPAN>
userCount <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'...Processing input users file at: '</SPAN> <SPAN class="operator token">+</SPAN> inUserFile
entryCount <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">for</SPAN> line <SPAN class="keyword token">in</SPAN> inFileHandle<SPAN class="punctuation token">.</SPAN>readlines<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
userParams <SPAN class="operator token">=</SPAN> line<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'|'</SPAN><SPAN class="punctuation token">)</SPAN>
userParamDict <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">if</SPAN> provider<SPAN class="operator token">==</SPAN><SPAN class="string token">"webadaptor"</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>userParams<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">5</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range <SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># login</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># email address</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># name</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># role</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>replace<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># description</SPAN>
usersQ<SPAN class="punctuation token">.</SPAN>put <SPAN class="punctuation token">(</SPAN>userParamDict<SPAN class="punctuation token">)</SPAN>
userCount <SPAN class="operator token">=</SPAN> userCount <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">' The format for entry %s is invalid. The format for enterprise accounts should be <login>|<email address>|<name>|<role>|<description>. \n '</SPAN><SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>entryCount<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">raise</SPAN> SystemExit<SPAN class="punctuation token">(</SPAN> <SPAN class="string token">'When registering enterprise accounts, the format for each entry is as follows: <login>|<email address>|<name>|<role>|<description>'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">elif</SPAN> provider<SPAN class="operator token">==</SPAN><SPAN class="string token">"arcgis"</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>userParams<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range <SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># account</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># password</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># email address</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># name</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># role</SPAN>
userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> userParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>replace<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># description</SPAN>
usersQ<SPAN class="punctuation token">.</SPAN>put <SPAN class="punctuation token">(</SPAN>userParamDict<SPAN class="punctuation token">)</SPAN>
userCount <SPAN class="operator token">=</SPAN> userCount <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">' The format for entry %s is invalid. The format for built-in portal accounts should be <account>|<password>|<email address>|<name>|<role>|<description>. \n '</SPAN><SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>entryCount<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">raise</SPAN> SystemExit<SPAN class="punctuation token">(</SPAN> <SPAN class="string token">'When registering built-in portal accounts, the format for each entry is as follows: <account>|<password>|<email address>|<name>|<role>|<description>'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">' The provider is incorrect. Script ended. \n'</SPAN>
<SPAN class="keyword token">raise</SPAN> SystemExit<SPAN class="punctuation token">(</SPAN> <SPAN class="string token">'The value for the user type is invalid. '</SPAN><SPAN class="punctuation token">)</SPAN>
entryCount <SPAN class="operator token">=</SPAN> entryCount <SPAN class="operator token">+</SPAN><SPAN class="number token">1</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>lower<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN> <SPAN class="string token">"user"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">or</SPAN> <SPAN class="punctuation token">(</SPAN>userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>lower<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN><SPAN class="string token">"publisher"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">or</SPAN> <SPAN class="punctuation token">(</SPAN>userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>lower<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN> <SPAN class="string token">"admin"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">raise</SPAN> SystemExit<SPAN class="punctuation token">(</SPAN> <SPAN class="string token">'The value for the user role %s in users text file is invalid. Accepted values are user or publisher or admin. '</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>userParamDict<SPAN class="punctuation token">[</SPAN>keyParams<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
inFileHandle<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create users and report results</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'...Total members to be added: '</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>userCount<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> usersQ
<SPAN class="comment token"># This function connects to the portal and adds members to it from a collection</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">createUsers</SPAN><SPAN class="punctuation token">(</SPAN>username<SPAN class="punctuation token">,</SPAN>password<SPAN class="punctuation token">,</SPAN> portalUrl<SPAN class="punctuation token">,</SPAN> provider<SPAN class="punctuation token">,</SPAN>userParamsQ<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'...Connecting to '</SPAN> <SPAN class="operator token">+</SPAN> portalUrl
token <SPAN class="operator token">=</SPAN> generateToken<SPAN class="punctuation token">(</SPAN>username<SPAN class="punctuation token">,</SPAN>password<SPAN class="punctuation token">,</SPAN> portalUrl<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'...Adding users '</SPAN>
usersLeftInQueue <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="keyword token">while</SPAN> usersLeftInQueue<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
userDict <SPAN class="operator token">=</SPAN> userParamsQ<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
userDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'f'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">'json'</SPAN>
userDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'token'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> token
userDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'provider'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> provider
params <SPAN class="operator token">=</SPAN> urllib<SPAN class="punctuation token">.</SPAN>urlencode<SPAN class="punctuation token">(</SPAN>userDict<SPAN class="punctuation token">)</SPAN>
request <SPAN class="operator token">=</SPAN> urllib2<SPAN class="punctuation token">.</SPAN>Request<SPAN class="punctuation token">(</SPAN>portalUrl <SPAN class="operator token">+</SPAN> <SPAN class="string token">'/portaladmin/security/users/createUser?'</SPAN><SPAN class="punctuation token">,</SPAN>params<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="string token">'Referer'</SPAN> <SPAN class="punctuation token">:</SPAN> portalUrl <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># POST the create request</SPAN>
response <SPAN class="operator token">=</SPAN> urllib2<SPAN class="punctuation token">.</SPAN>urlopen<SPAN class="punctuation token">(</SPAN>request<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>read<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
responseJSON <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Log results</SPAN>
<SPAN class="keyword token">if</SPAN> responseJSON<SPAN class="punctuation token">.</SPAN>has_key<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'error'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
errDict <SPAN class="operator token">=</SPAN> responseJSON<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'error'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> int<SPAN class="punctuation token">(</SPAN>errDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'code'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN><SPAN class="number token">498</SPAN><SPAN class="punctuation token">:</SPAN>
message <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Token Expired. Getting new token... Username: '</SPAN> <SPAN class="operator token">+</SPAN> userDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'username'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">' will be added later'</SPAN>
token <SPAN class="operator token">=</SPAN> generateToken<SPAN class="punctuation token">(</SPAN>username<SPAN class="punctuation token">,</SPAN>password<SPAN class="punctuation token">,</SPAN> portalUrl<SPAN class="punctuation token">)</SPAN>
userParamsQ<SPAN class="punctuation token">.</SPAN>put<SPAN class="punctuation token">(</SPAN>userDict<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
message <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Error Code: %s \n Message: %s'</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>errDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'code'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
errDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'message'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'\n'</SPAN> <SPAN class="operator token">+</SPAN> message
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Success</SPAN>
<SPAN class="keyword token">if</SPAN> responseJSON<SPAN class="punctuation token">.</SPAN>has_key<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'status'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
resultStatus <SPAN class="operator token">=</SPAN> responseJSON<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'status'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'User: %s account created'</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>userDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'username'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'User: %s account created'</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>userDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'username'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> Queue<SPAN class="punctuation token">.</SPAN>Empty<SPAN class="punctuation token">:</SPAN>
usersLeftInQueue <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
<SPAN class="comment token"># This function gets a token from the portal</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">generateToken</SPAN><SPAN class="punctuation token">(</SPAN>username<SPAN class="punctuation token">,</SPAN> password<SPAN class="punctuation token">,</SPAN> portalUrl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">'''Retrieves a token to be used with API requests.'''</SPAN>
parameters <SPAN class="operator token">=</SPAN> urllib<SPAN class="punctuation token">.</SPAN>urlencode<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">'username'</SPAN> <SPAN class="punctuation token">:</SPAN> username<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'password'</SPAN> <SPAN class="punctuation token">:</SPAN> password<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'client'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'referer'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'referer'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'https://domain.com'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'expiration'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="number token">60</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'f'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'json'</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
response <SPAN class="operator token">=</SPAN> urllib<SPAN class="punctuation token">.</SPAN>urlopen<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'https://domain.com/arcgis/sharing/rest/generateToken?'</SPAN><SPAN class="punctuation token">,</SPAN>
parameters<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>read<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> Exception <SPAN class="keyword token">as</SPAN> e<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN> <SPAN class="string token">'Unable to open the url %s/sharing/rest/generateToken'</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>portalUrl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
responseJSON <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">.</SPAN>strip<SPAN class="punctuation token">(</SPAN><SPAN class="string token">' \t\n\r'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Log results</SPAN>
<SPAN class="keyword token">if</SPAN> responseJSON<SPAN class="punctuation token">.</SPAN>has_key<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'error'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
errDict <SPAN class="operator token">=</SPAN> responseJSON<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'error'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> int<SPAN class="punctuation token">(</SPAN>errDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'code'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN><SPAN class="number token">498</SPAN><SPAN class="punctuation token">:</SPAN>
message <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Token Expired. Getting new token... '</SPAN>
token <SPAN class="operator token">=</SPAN> generateToken<SPAN class="punctuation token">(</SPAN>username<SPAN class="punctuation token">,</SPAN>password<SPAN class="punctuation token">,</SPAN> portalUrl<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
message <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Error Code: %s \n Message: %s'</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>errDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'code'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
errDict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'message'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">raise</SPAN> SystemExit<SPAN class="punctuation token">(</SPAN>message<SPAN class="punctuation token">)</SPAN>
token <SPAN class="operator token">=</SPAN> responseJSON<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'token'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> token
<SPAN class="comment token"># This function gets gets parameters from the user in interactive mode</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">getParametersFromUser</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
parameters <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token"># Get Location of users file</SPAN>
inUserFile <SPAN class="operator token">=</SPAN> raw_input <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Enter path to users text file: "</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>exists<SPAN class="punctuation token">(</SPAN>inUserFile<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">' File does not exist. Script ended. \n'</SPAN>
<SPAN class="keyword token">raise</SPAN> SystemExit<SPAN class="punctuation token">(</SPAN> <SPAN class="string token">'Input file: %s does not exist'</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>inUserFile<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'inUserFile'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> inUserFile
<SPAN class="comment token"># Enteprise logins or built-in accounts?</SPAN>
userInput <SPAN class="operator token">=</SPAN> raw_input <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"What type of users do you want to add to the portal? Accepted values are built-in or enterprise: "</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> userInput<SPAN class="punctuation token">.</SPAN>lower<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN><SPAN class="string token">"built-in"</SPAN><SPAN class="punctuation token">:</SPAN>
parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'provider'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">'arcgis'</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">' Built-in accounts will be added to the portal. \n'</SPAN>
<SPAN class="keyword token">elif</SPAN> userInput<SPAN class="punctuation token">.</SPAN>lower<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN><SPAN class="string token">"enterprise"</SPAN><SPAN class="punctuation token">:</SPAN>
parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'provider'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">'webadaptor'</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">' Enterprise accounts will be added to the portal. \n'</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">' The type of users is incorrect. Script ended. \n'</SPAN>
<SPAN class="keyword token">raise</SPAN> SystemExit<SPAN class="punctuation token">(</SPAN> <SPAN class="string token">'The value entered for the user type %s is invalid. Accepted values are built-in or enterprise. '</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>userInput<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Get Portal URL</SPAN>
hostname <SPAN class="operator token">=</SPAN> raw_input<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Enter the fully qualified portal hostname (for example myportal.acme.com): "</SPAN><SPAN class="punctuation token">)</SPAN>
parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'portalURL'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">'https://'</SPAN> <SPAN class="operator token">+</SPAN> hostname <SPAN class="operator token">+</SPAN> <SPAN class="string token">'/arcgis'</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">' Users will be added to portal at: '</SPAN> <SPAN class="operator token">+</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'portalURL'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN>
<SPAN class="comment token"># Get a username and password with portal administrative privileges</SPAN>
parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'userName'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> raw_input<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Enter a built-in user name with portal administrative privileges:"</SPAN><SPAN class="punctuation token">)</SPAN>
parameters<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'password'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> raw_input<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Enter password: "</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'\n'</SPAN>
<SPAN class="keyword token">return</SPAN> parameters
<SPAN class="comment token"># Script start</SPAN>
<SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">"__main__"</SPAN><SPAN class="punctuation token">:</SPAN>
sys<SPAN class="punctuation token">.</SPAN>exit<SPAN class="punctuation token">(</SPAN>main<SPAN class="punctuation token">(</SPAN>sys<SPAN class="punctuation token">.</SPAN>argv<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>The code work's fine but at the moment of add users the web service return the next message:
"Error 500, Failed to register member xyz (xyz @domain.com). The number of registered portal members is equal to or greater than the number of licensed members"
But all i have is one built-in user (the native portal admin) and one more admin added from LDAP and i have enough licences to add new lvl 2 users, in fact in the organization tab i can see that i have 2 / 5 lvl 2 licences used, so i have 3 to add new users, what i'm attempting to add is a regular lvl 2 "user" role:
xxx2682|xxxx2682@domain.com|xxx2682|user|test
i have already tried add users directly from the organization tab and i can do it.
Can anyone help me with this? there is any solution?
Thanks.