8

Sometimes when I run a Python script from IDLE that uses the ArcPy installed with ArcGIS Pro 1.4.1 the script will abort with RuntimeError: Not signed into Portal:

RESTART: C:\temp\test.py 
Traceback (most recent call last):
  File "C:\temp\test.py", line 9, in <module>
    import arcpy
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 66, in <module>
    from arcpy.geoprocessing import gp
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\__init__.py", line 14, in <module>
    from ._base import *
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 14, in <module>
    import arcgisscripting
RuntimeError: Not signed into Portal.

If I do nothing other than run the script again, in exactly the same way, using the same Python shell and script windows, then it will usually just work. Very occasionally I may have to try running it a third time. At a very rough estimate it works 90% first time, 9% second time and 1% third time.

I have seen the same error on two machines running two versions and two different license sources:

  • ArcGIS Pro 1.4.1 sourcing its license from ArcGIS for Portal
  • ArcGIS Pro 1.3.1 sourcing its license from ArcGIS Online

In both configurations I have not tested using Authorize ArcGIS Pro to work offline so all tests have been run while working online.

Does anyone know a likely cause for this error, and any way to try and avoid it occurring?

The same error seems to have been seen deep in a GeoNet forum thread and suggests that it is related to logging out of ArcGIS Online while running the script. However, I am running my script while ArcGIS Pro is open (but not being used), and I am not logged in via a browser to ArcGIS.com so I think the advice offered there does not apply.

5 Answers 5

7

As you're licensed ArcGIS Pro from portal/online, I suspect you have not "authorized ArcGIS Pro to work offline" (an option available in the backstage).

I bring this up, as the error you're getting, about not being signed in, is most likely due to the session expiring or not being able to refresh itself. Python does not have a direct way to authenticate to the portal to license Pro. It relies on Pro to be licensed. (And you authenticate your license when using a named user by signing into the portal via the popup box)

So what to do? Like I said, you can authorize Pro to work offline from the backstage. Otherwise if you encounter this error you'll need to open Pro and "refresh" your connection to the license.

Note - being logged into arcgis.com via a browser has absolutely nothing to do with licensing Pro. You might be using the same account, but being logged in there does not authenticate ArcGIS Pro.

This may not answer your question specifically. It answers the generic "I get an error about not being logged in when running my stand alone script". You've stated:

I am running my script while ArcGIS Pro is open

....because of that, I can't explain why you'd receive the error.

5
  • You've taught me a little more about the licensing considerations and options available so I'm happy to accept your answer even though it sounds like I should not see this error. At least I now have confidence that if it becomes an issue for my users then I can recommend that they try working offline, at least temporarily.
    – PolyGeo
    Commented May 3, 2017 at 22:34
  • 1
    I've seen you use the term backstage here a couple of times recently and have figured that it is what I have been calling the "project page". I notice that the term only appears once in all of ArcGIS Pro's web help (excluding SDK): desktop.arcgis.com/search/… I'm assuming that it is a term that I should switch to using if I want to stay in sync with ArcGIS Pro's designers. It is a term I like and I think it might be useful to change the PROJECT tab name to BACKSTAGE.
    – PolyGeo
    Commented May 3, 2017 at 22:39
  • 1
    I can't speak to the use of the term "backstage" in the doc.... I know Microsoft uses it: support.office.com/en-us/article/…. I just assume it's a standard term for settings in this place (whether or not that's correct I don't know)
    – KHibma
    Commented May 3, 2017 at 22:47
  • I guess I should be saying "application options" pro.arcgis.com/en/pro-app/get-started/…
    – KHibma
    Commented May 3, 2017 at 22:48
  • This is still an issue at Pro 2.3.2. Opening up Pro to "refresh" my connection worked for me. Commented May 15, 2019 at 21:54
2

You could try using "propy.bat" or "proenv.bat".

One loads environments for stand-alone scripts and the other loads the environment for an interactive session.

http://pro.arcgis.com/en/pro-app/arcpy/get-started/using-conda-with-arcgis-pro.htm

1
  • 1
    I'm not currently in a position to test this because that environment is only available at one of my sites. I'll look back at your answer if it arises as an issue there or anywhere else.
    – PolyGeo
    Commented Jan 23, 2018 at 22:32
2

I had this same error, and was able to resolve it with the help of the above 2 answers. I used propy.bat as my python executable, and I ran it in an administrator shell. Apparently the sign-in portal validation with arcpy needs to happen with administrator elevation.

1

Use the SignInToPortal python function at the beginning of your Python script. This should force it to sign into the portal.

http://pro.arcgis.com/en/pro-app/arcpy/functions/signintoportal.htm

Something like:

import arcpy
arcpy.SignInToPortal(arcpy.GetActivePortalURL(), 'username', 'password')

or

import arcpy
arcpy.SignInToPortal('https://www.arcgis.com/', 'username', 'password')

should do the trick. If you open Pro, click Project, then click Portals, you can see the portal URL on screen.

4
  • 3
    This doesn't work in my case, since it's the import arcpy line which causes the RuntimeError: Not signed into Portal error message. ie there's no chance to even run the SignInToPortal command Commented Jan 17, 2019 at 2:04
  • 1
    @StephenLead yes you are right. I signed out of the portal on ArcGIS Pro then tried to run my script: it did indeed fail with the error you mentioned. Hmmm... I need another solution.
    – Theo F
    Commented Jan 17, 2019 at 11:08
  • 2
    I can confirm that if the "authorize ArcGIS Pro to work offline" setting has been checked on, it's possible to import arcpy, and thereafter to use the SignInToPortal command. You can put the import arcpy line inside a try/except block to handle the import error Commented Jan 24, 2019 at 22:04
  • For those looking, this is how you can "authorize ArcGIS Pro to work offline": pro.arcgis.com/en/pro-app/get-started/… The caveat here is this locks that user account to only be able to use Pro on that one machine. However, if you only run scripts from one server, and can afford to lock up a license, this is the way to go.
    – alexGIS
    Commented Jul 19, 2019 at 16:25
1

If running scripts with a service account, the Pro profile has to be created in C:\Users\user\AppData\Roaming\Esri for it by logging into the machine with the service account and logging into Pro. Then, the service account can call propy.bat offline, which will reference that profile. I did not have to authorize Pro to work offline but did check Sign me in automatically.

ArcPy fails to import when not logged into host machine

I also had to grant my service account the ability to run batch scripts. See batch file from scheduled task returns code 2147942401.

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.