Unable to connect to ArcGis Enterprise Portal via python using token

10-23-2019 06:22 AM
New Contributor III


I want to connect to our ArcGis Entreprise portal in a python script using a valid token, but it fails ....

I execute this script from ArcGis Pro connected to our portal.

#My script "Script"

import arcgis.gis
import arcgis.gis.admin
import arcgis.gis.server

ent_gis = arcgis.gis.GIS(url=arcpy.GetActivePortalURL(),token=arcpy.GetSigninToken())


Start Time: mercredi 23 octobre 2019 15:01:01
Running script Script...
Failed script Script...
 Traceback (most recent call last):
  File "C:\Users\freval-s\Documents\ArcGIS\Projects\MyProject5\portal_ent.py", line 6, in <module>
    ent_gis = arcgis.gis.GIS(url=arcpy.GetActivePortalURL(),token=arcpy.GetSigninToken())
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 381, in __init__
    self._lazy_properties = PropertyMap(self._portal.get_properties(force=force_refresh))
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\portalpy.py", line 1088, in get_properties
    if resp:
UnboundLocalError: local variable 'resp' referenced before assignment
 Failed to execute (Script).
Failed at mercredi 23 octobre 2019 15:01:07 (Elapsed Time: 5,80 seconds)

0 Kudos
2 Replies
New Contributor III

This is how the getting started notebooks (Click on link Using Oauth 2.0) showed me how to access portal content.

Create a Python application on your portal

1. Sign In to Portal

2. Go to My Content

3. Click on Add Item and select application

4. Dialog appears and select Application

5. Name the application Python and give it a tag Python

6. Go to Settings under the application you just created and grab the client id

After you create the portal python application, Use the following code in your notebook

import arcgis
from arcgis.gis import GIS

gis = GIS("https://<portal address>/portal",client_id='###########') #client id is the id assigned to the python application

0 Kudos
New Contributor

i am facing the same issue. service sigu please let me know if you solved it .


0 Kudos