AnsweredAssumed Answered

ArcGIS Server - AttributeError: module 'arcpy' has no attribute 'ImportCredentials'

Question asked by ChrisCorliss on Apr 9, 2019
Latest reply on Sep 6, 2019 by ChrisCorliss

I have a geoprocessing service on my standalone ArcGIS Server v10.6.1 to perform advanced printing for web maps using from ArcGIS Pro v2.3.1. Our application accesses secure services so I need to include the arcpy.ImportCredentials function. When I run the script I get the following error:


Error executing tool. ConvertPdf : Traceback (most recent call last): File "D:\arcgisserver\directories\arcgissystem\arcgisinput\GP\ConvertPdf.GPServer\extracted\p20\arcgis_project\", line 36, in importedConnections = arcpy.ImportCredentials(secure_server_connections) AttributeError: module 'arcpy' has no attribute 'ImportCredentials' Failed to execute (ConvertPdf). Failed to execute (ConvertPdf).


If I remove the ImportCredentials function, the script works and generates an image (if my web map json doesn't include a secure service).


We are not using Portal and therefore this is not a federated server. So I am not able publish this service as a web tool. I had to write a script to create a service draft using arcpy.CreateGPSDDraft and used UploadServiceDefinition to publish to our server. The service appears to be using the propy python environment because it successfully uses the module, but I don't know why it fails on ImportCredentials.


Here is the code published to the server:

import arcpy
import os
import uuid

# The template location in the server data store
scriptPath = sys.path[0]
templatePath = os.path.join(scriptPath, 'Templates')

# Input WebMap JSON
Web_Map_as_JSON = arcpy.GetParameterAsText(0)

# Input layout template
Layout_Template = arcpy.GetParameterAsText(1)

# Get the requested layout template pagx file
templatePagx = os.path.join(templatePath, Layout_Template + '.pagx')

# Specify credentials for secured services in the WebMap JSON
secure_server_connections = [
    os.path.join(scriptPath, 'creds.ags'),

# Import credentials
importedConnections = arcpy.ImportCredentials(secure_server_connections)
# Convert the WebMap to an ArcGISProject
result =, templatePagx, 'LetterLandscape')
aprx = result.ArcGISProject
layout = aprx.listLayouts()[0]

# Set scale
scale = arcpy.GetParameterAsText(3)
layout = aprx.listLayouts('LetterLandscape')[0]
mapframe = layout.listElements('MapFrame_Element')[0] = scale

# Set rotation
rotate = arcpy.GetParameterAsText(4) = rotate
# Use the uuid module to generate a GUID as part of the output name
# This will ensure a unique output name
output = 'WebMap_{}.png'.format(str(uuid.uuid1()))
Output_File = os.path.join(arcpy.env.scratchFolder, output)

# Export the WebMap
dpi = arcpy.GetParameterAsText(5)
layout.exportToPNG(Output_File, int(dpi))

# Set the output parameter to be the output file of the server job
arcpy.SetParameterAsText(2, Output_File)

# Clear credentials

# Clean up
del layout, aprx, result


Any ideas on how I can get this to work on our server?