While using ArcGIS Pro, I am trying to run the Find Closest Facility tool inside a Python For loop. I found some helper code in the tool information rollover in Pro that goes through these steps:

username = "<your user name>"
password = "<your password>"
cf_service = "https://www.arcgis.com".format(username, password)

#Add the geoprocessing service as a toolbox. Use an alias when importing
arcpy.ImportToolbox(cf_service, "agol")

#Set the variables to call the tool
facilities = r"C:/data/Inputs.gdb/Stores"
incidents = r"C:/data/Inputs.gdb/Customers"
output_routes = "C:/data/Results.gdb/Routes"
output_directions = "C:/data/output/Results.gdb/Directions"

#Call the tool
result = arcpy.agol.FindClosestFacilities(incidents, facilities, "Minutes", "", 2)

After entering my user/pass, I tried to import the Find Closest Facilities tool from AGOL and was presented with this error:

"OSError: The toolbox file http://logistics.arcgis.com/arcgis/services;World/ClosestFacilty;<username>;<password> was not found."

My user account is an Admin so I should have privileges to call this tool from AGOL to run inside of a Python script. Perhaps, I'm calling it incorrectly? I tried using the URL above, as well as, our AGOL portal URL.

What I'm ultimately trying to do is to just run the "FindClosestFacilties" tool in a Python script, so if anyone has an alternative to the above Esri code, that would be helpful.

  • I've not attempted to use the tool you are using or familiar with calling server side tools but just looking at the error message I would have as a guess that it's the ; between services and World that is upsetting things?
    – Hornbydd
    Commented Feb 6, 2018 at 10:09

1 Answer 1


It looks like your code fragment for the following is incomplete:

cf_service = "https://www.arcgis.com".format(username, password)
#Add the geoprocessing service as a toolbox. Use an alias when importing
arcpy.ImportToolbox(cf_service, "agol")

I'd take another look at the ImportToolbox help.

If you're inside Pro or outside Pro and logged in, you can use the following... the UseSSOIdentityIfPortalowned makes use of being logged in to get a token and authenticate. This will be the easiest to get up and running.

tbx = "http://logistics.arcgis.com/arcgis/services;World/ServiceAreas;UseSSOIdentityIfPortalOwned"

Based on your code, you're passing a username and password. You can only use the username/password input syntax if you're connecting directly to an ArcGIS Server. In your snippet you're pointing at ArcGIS.com, this is a Portal. So you're mixing and matching code snippets from the ImportToolbox. If you want to pass the user/pass like you are, you'll need to create an .AGS connection file to a server that makes use of the logistic service. (Instead of a http url like you have). If you want to use the Portal (arcgis.com) version, you'll need to obtain a token and can use that syntax from the help link referenced above. You can get a token in Python, or if you're signed in using Pro, you can use arcpy.GetSigninToken() to obtain one.

  • Looks like UseSSOIdentityIfPortalowned did the trick. Thanks @KHibma!
    – Dave
    Commented Feb 12, 2018 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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