The ClearCredentials function removes ArcGIS Server credential information from a client machine to disable access to secured services.
Credential information can be imported using the arcpy.ImportCredentials function. The ClearCredentials function can be used to remove ArcGIS Server credential information from a client machine to disable access to secured services when finished. The ClearCredentials function can also be used to print web maps that contain secured services from ArcGIS Server.
A list of dictionaries with key-value pairs of credential information obtained from the arcpy.ImportCredentials function.
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() # 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)