I created an ESRI Python toolbox and setup one of the parameters of the toolbox as an encrypted string as the parameter is a location for the end user to enter a password.

The problem I am encountering is getting that string un-encrypted from the parameter using the only method I have ever used parameters[0].valueAsText and the only method I could find in the ESRI documentation. This method keeps the string encrypted. Subsequently, I encounter errors when trying to use this parameter in the rest of the script. I'm using ArcGIS Desktop 10.3

 def getParameterInfo(self):
    """Define parameter definitions"""

    param0 = arcpy.Parameter(displayName = 'AGOL Username',
    name = 'AGOL Username',
    datatype ='GPString',
    parameterType ="Required",
    direction ="Input")

    param1 = arcpy.Parameter(displayName = 'AGOL Password',
    name = 'AGOL Password',
    datatype ='GPEncryptedString',
    parameterType ="Required",
    direction ="Input")

    param2 = arcpy.Parameter(displayName = 'AGOL Group ID',
    name = 'AGOL Group ID found in the URL, when viewing group in AGOL',
    datatype ='GPString',
    parameterType ="Required",
    direction ="Input")

    param3 = arcpy.Parameter(displayName = 'Output Folder',
    name = 'OutPut Folder to Store Zipped Downloaded Feature Services',
    datatype ='DEFolder',
    parameterType ="Required",
    direction ="Input")

    params = [param0, param1, param2, param3]
    return params

def isLicensed(self):
    """Set whether tool is licensed to execute."""
    return True

def updateParameters(self, parameters):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""

def updateMessages(self, parameters):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""

def execute(self, parameters, messages):
    """The source code of the tool."""
    import os #,tempfile, shutil
    #import zipfile
    import json #, re
    #import uuid
    import  time #datetime,
    import urllib,urllib2
    #import sys

    username = parameters[0].valueAsText
    password = parameters[1].valueAsText
    groupid =  parameters[2].valueAsText 
    outputLocation = parameters[3].valueAsText
  • Please Edit the question to specify the release of ArcGIS in use. – Vince Jun 7 '18 at 18:42

You can't use the encrypted string parameter to do what you're trying to do. Encrypted string is for Esri components that accept an encrypted strings. Basically for passing a password to an enterprise geodatabase. Basically the Create ArcSDE Connection file tool uses this.

The best you can do is use a String - Hidden. This masks the string in the UI. However its still plain text in the back end. If you want to do actual encryption, you'll need to handle that yourself. There is no tool parameter to do it for you.

See this: Handling user password input in ArcPy scripts?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.