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:
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> <SPAN class="operator token">*</SPAN>
<SPAN class="keyword token">from</SPAN> IPython<SPAN class="punctuation token">.</SPAN>display <SPAN class="keyword token">import</SPAN> display<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
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 <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2F" target="_blank">https://</A><SPAN>{{ MY_ORG }}.maps.arcgis.com"</SPAN></SPAN><SPAN class="punctuation token">,</SPAN> client_id<SPAN class="operator token">=</SPAN><SPAN class="string token">'{{MY_APP_ID}}'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Successfully logged in as: "</SPAN> <SPAN class="operator token">+</SPAN> gis<SPAN class="punctuation token">.</SPAN>properties<SPAN class="punctuation token">.</SPAN>user<SPAN class="punctuation token">.</SPAN>username<SPAN class="punctuation token">)</SPAN>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 }}<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>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 <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'{{SOME ITEM ID}}'</SPAN><SPAN class="punctuation token">)</SPAN>
display<SPAN class="punctuation token">(</SPAN>item<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>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)<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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?