arcpy.SignInToPortal "Failed to sign out" error

02-04-2021 12:52 PM
New Contributor II

I am trying to create a map service definition file in Python (see a snippet below). The code fails on the line arcpy.SignInToPortal:

arcpy.SignInToPortal("****", "****", "****")
File "D:\ArcGIS\Pro\Resources\ArcPy\arcpy\", line 2468, in SignInToPortal
return _SignInToPortal(*args, **kwargs)
ValueError: Failed to sign out.

I confirmed that I am not logged in to the portal on the machine which the script is executed. The portal URL and the user credentials are correct as well. Why am I getting the error and how to get around it? Thanks! 


arcpy.SignInToPortal(portalURL, "MyUserName""MyPassword")

    sharingDraft = mp.getWebLayerSharingDraft("HOSTING_SERVER""FEATURE", serviceName)
    sharingDraft.portalURL = portalURL
    sharingDraft.portalFolder = serviceFolderName
    sharingDraft.description = newDescription
    sharingDraft.summary = "[Summary]"
    sharingDraft.tags = "[Tags]"
    sharingDraft.credits = "[Credits]"
    sharingDraft.useLimitations = "[Limitations]"
    sharingDraft.copyDataToServer = False

    arcpy.StageService_server(sdDraftFilePath, sdOutputFilePath)


5 Replies
by Anonymous User
Not applicable

Hi @azlotin,

My first guess would be the Portal URL.
I know that you have checked that it is correct, but do you have the real string identifier in front of the string?
e.g: r"https://<portal webadaptor url>/<webadaptor name>/"

If you have, then I would be looking to see if the script can ping the server first as t may be a network issue as well.



Occasional Contributor III

Did you ever get this resolved? I'm running into a similar issue. 

0 Kudos
New Contributor III

I think Michael is spot on with the portal URL.

I ran into the same problem today, and found out that the portal URL read from a configuration file was something like this:


When I changed to 


everything worked!


MVP Regular Contributor

I second @CarstenB_orsted .

This worked for signing in to AGOL:

# Sign in to AGOL
arcpy.SignInToPortal("", "user", "pass")

arcpy.SignInToPortal(r"", "user", "pass")


This didn't work:

arcpy.SignInToPortal("", "user", "pass")

arcpy.SignInToPortal(r"", "user", "pass")
Occasional Contributor III

For us - this seems to be related to a self signed cert error.  If using the Python API, GIS('myportalurl', username, password) fails with ssl validation error unless I add verify_cert=False as a parameter.  The problem is, there is no way to do this using Arcpy.SignInToPortal, which is required for programmatically publishing services.  

0 Kudos