English

Problem: Unable to log in to ArcGIS Online using ArcPy

Description

Attempting to log in to ArcGIS Online using ArcPy sometimes fails, and returns the following warning message:

Warning:
001561: ArcGIS Online/Portal authorization requires direct sign in

The following shows a sample failed script:

import arcpy

userName = "user1"
passWord = "password1"

# For ArcMap
arcpy.SignInToPortal_server(userName, passWord, "http://www.arcgis.com/")

# For ArcGIS Pro
arcpy.SignInToPortal(arcpy.GetActivePortalURL(), 'username', 'password') 

print arcpy.GetMessages()

Cause

There are two possible causes:

  • The Sign In To Portal tool ignores input values for the portal_url parameter, and reads the URL set in ArcGIS Administrator. If the portal URL is absent in ArcGIS Administrator, the warning message is returned, and login to ArcGIS Online fails. Refer to ArcMap: Sign In To Portal for more information.
  • The Sign In To Portal tool is executed using a stand-alone script. This function is not supported and is a known limitation.

Solution or Workaround

Add the portal_url value in ArcGIS Administrator.

  1. Open ArcGIS Administrator.
  2. Select the node of the machine, and click Advanced to open the Advanced Configuration window.
ArcGIS Administrator window
  1. Click Manage Portal Connections to open the Manage Portal for ArcGIS Connections window.
    1. Click Add. Insert http://www.arcgis.com/ and click OK.
Manage Portal for ArcGIS Connections window
  1. Click Connect.
  2. Click Save > Ok.

After adding the portal_URL parameter in ArcGIS Administrator, the syntax in the SignInToPortal tool for ArcMap is empty, as shown below.

arcpy.SignInToPortal_server(userName, passWord, "")

To run the code outside of ArcGIS Pro or ArcMap, the following conditions must be met:

Related Information