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

3695
6
Jump to solution
04-09-2019 12:49 PM
ChristopherCorliss1
New Contributor II

I have a geoprocessing service on my standalone ArcGIS Server v10.6.1 to perform advanced printing for web maps using arcpy.mp.ConvertWebMapToArcGISProject 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\WebMapToArcGISProject.py", 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 arcpy.mp 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 = arcpy.mp.ConvertWebMapToArcGISProject(Web_Map_as_JSON, 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]
mapframe.camera.scale = scale

# Set rotation
rotate = arcpy.GetParameterAsText(4)
mapframe.camera.heading = 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
arcpy.ClearCredentials(importedConnections)

# Clean up
del layout, aprx, result

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

Thanks

0 Kudos
1 Solution

Accepted Solutions
TanuHoque
Esri Regular Contributor

ImportCredentials() was introduced in Pro 2.3 release. On the server side, you need 10.7 or higher.

View solution in original post

6 Replies
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Hi Christopher

Have you found a solution for this? I am having the same issue here...

Cheers

0 Kudos
TanuHoque
Esri Regular Contributor

ImportCredentials() was introduced in Pro 2.3 release. On the server side, you need 10.7 or higher.

simoxu
by MVP Regular Contributor
MVP Regular Contributor

Thanks for giving the clarification. we are on 10.6.1.

0 Kudos
ChristopherCorliss1
New Contributor II

Thanks Tanu Hoque‌. We are also on 10.6.1.

0 Kudos
PatSmyth
New Contributor III

@TANH is the only solution to this problem to upgrade an ArcGIS Server instance to 10.7 or higher? I have a arcpy.mp geoprocessing service that is trying to access premium layers in an aprx and, while this works locally before publishing, it will not work when running on our ArcGIS Server install at 10.6.1. Without the ImportCredentials module available, I don't see any other options short of doing a full upgrade. Is that right? Could I just port the geoprocessing service over to arcpy.mapping and python 2.7 to use the equivalent there? Thanks in advance

0 Kudos
TanuHoque
Esri Regular Contributor

@PatSmyth 

yes, that is correct. you need to update your server to 10.7 or higher. And then use ArcGIS Pro 2.3 or higher to publish your service from.

0 Kudos