When connecting to my organizational AGOL account via the Python API, I have found lately that while the login appears to succeed, I do not have the same level of access to my items that I have when accessing them through the AGOL browser interface or ArcGIS Pro.
Setup
- OS: Windows 10
- Python Version: 3.5 on Anaconda.
NOTE: This is not the an environment from the Anaconda installation that comes with ArcGIS Pro. This is an installation I had prior to installing ArcGIS Pro. (requirements.txt attached) - ArcGIS Python API Version: 1.4.2
First, I import my packages:
from arcgis.gis import *
from IPython.display import display
My organizational account must be authenticated via OAuth 2.0. I have followed the instructions here for authenticating with OAuth 2.0. I have created an application called Python and used the following code to login.
gis = GIS("https://{{ MY_ORG }}.maps.arcgis.com", client_id='{{MY_APP_ID}}')
print("Successfully logged in as: " + gis.properties.user.username)
This appears to work with no problem as there are no errors returned and the following statement is printed:
Successfully logged in as: {{ MY USERNAME }}
However, problems arise when I try to access any of my items. Note, by "my items" I mean those for which I am the item owner. For the sake of example, let's say I try to access an item by its item number:
item = gis.content.get('{{SOME ITEM ID}}')
display(item)
This throws the following error
You do not have permissions to access this resource or perform this operation.
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-3-faf871f03a5b> in <module>()
----> 1 gis.content.get('{{ SOME ITEM ID }}')
~\Miniconda3\envs\arcpython\lib\site-packages\arcgis\gis\__init__.py in get(self, itemid)
2653 return None
2654 else:
-> 2655 raise re
2656
2657 if item is not None:
~\Miniconda3\envs\arcpython\lib\site-packages\arcgis\gis\__init__.py in get(self, itemid)
2648 """
2649 try:
-> 2650 item = self._portal.get_item(itemid)
2651 except RuntimeError as re:
2652 if re.args[0].__contains__("Item does not exist or is inaccessible"):
~\Miniconda3\envs\arcpython\lib\site-packages\arcgis\_impl\portalpy.py in get_item(self, itemid)
1206 ================ ========================================================
1207 """
-> 1208 return self.con.post('content/items/' + itemid, self._postdata())
1209
1210 def get_item_data(self, itemid, try_json=True):
~\Miniconda3\envs\arcpython\lib\site-packages\arcgis\_impl\connection.py in post(self, path, postdata, files, ssl, compress, is_retry, use_ordered_dict, add_token, verify_cert, token, try_json, out_folder, file_name, force_bytes, add_headers)
1154 verify_cert=verify_cert, is_retry=True)
1155
-> 1156 self._handle_json_error(resp_json['error'], errorcode)
1157 return None
1158
~\Miniconda3\envs\arcpython\lib\site-packages\arcgis\_impl\connection.py in _handle_json_error(self, error, errorcode)
1175
1176 errormessage = errormessage + "\n(Error Code: " + str(errorcode) +")"
-> 1177 raise RuntimeError(errormessage)
1178
1179 class _StrictURLopener(request.FancyURLopener):
RuntimeError: You do not have permissions to access this resource or perform this operation.
(Error Code: 403)
I have tested this process under a few different scenarios and not had these permission errors arise:
- On the same machine as this example, if I use the arcgispro-py3 environment with the Anaconda installation that comes with ArcGIS Pro, I am able to authenticate and access my items.
- Again, on the same machine as this example, if I have ArcGIS Pro running, I can use Pro to authenticate. However, I must also be using the arcgispro-py3 environment with the Anaconda installation that comes with ArcGIS Pro.
- Using an entirely different machine running Ubuntu, I created the same environment OAuth 2.0 process as above and was successful in accessing my content.
Has anyone encountered this issue before? Any thoughts on how to troubleshoot?