Skip to main content

ImportCredentials

Summary

Imports credentials from a GIS server connection file for ArcGIS Server nontoken-based secured services.

Discussion

The ImportCredentials function can be used to access ArcGIS Server nontoken-based secured services from GIS server connection files. Credentials can be stored in connection files that are created in ArcGIS Pro. See Connect to a GIS server for more information regarding creating connection files. The ImportCredentials function can also be used to print web maps that contain secured services from ArcGIS Server. When you're finished importing credentials, you can clear them using the ClearCredentials function.

Syntax

ImportCredentials(secure_server_connections)

Parameter Explanation Data Type

secure_server_connections

A list of credentials for secured services. Credentials can be stored in connection files that are created in ArcGIS Pro.

The following connection file types are supported:

  • ArcGIS Server (.ags)

  • WMS Server (.wms)

  • WMTS Server (.wmts)

String

Return value

Data Type Explanation

Dictionary

Returns a list of dictionary key-value pairs of credential information that can be used in the ClearCredentials function.

Code sample

ImportCredentials example
import arcpy

# Import credentials
secured_credentials = arcpy.ImportCredentials([r"C:\Project\SecuredServices.ags"])
aprx = arcpy.mp.ArcGISProject(r"C:\Project\USA.aprx")
m = aprx.listMaps()[0]

# Add secured service to map
m.addDataFromPath('http://SampleServer:6080/arcgis/rest/services/secured/ProjectArea/FeatureServer/0')

# Clear credentials when finished
arcpy.ClearCredentials(secured_credentials)