Select to view content in your preferred language

Python API failing when in GP service

675
1
07-25-2022 08:29 AM
JasonJordan00
Frequent Contributor

Scratching my head trying to get a geoprocessing tool to work. If I run it in Pro or standalone in Pycharm it works fine, but when I publish and run it as a service it fails when trying to connect to the GIS. Locally, it works if I try either gis = GIS("home") or gis = GIS("https://........), but I get a "staging error" when I try to publish a tool using the latter method (the log just says error 999999).

I tried doing a test with a 3 line tool and as soon as it gets to line 3 its fails

import arcpy
from arcgis import GIS
gis = GIS('https://.....')

 

Trying on a federated Enterprise 10.9.1 using IWA login. Guessing its not pulling credentials correctly based on the error below. We have a second portal which is not IWA and using GIS('home') works fine on it.

Traceback (most recent call last): File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 610, in _handle_response data = resp.json() File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\requests\models.py", line 900, in json return complexjson.loads(self.text, **kwargs) File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\json\__init__.py", line 348, in loads return _default_decoder.decode(s) File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1929, in _check_product baseurl + "/info", params={"f": "json"}, add_token=False File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 506, in get ignore_error_key=ignore_error_key, File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 613, in _handle_response raise Exception(resp.text) Exception:

Server Error

 

401 - Unauthorized: Access is denied due to invalid credentials.

You do not have permission to view this directory or page using the credentials that you supplied.

During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 3, in File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 483, in __init__ raise e File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 444, in __init__ proxy=kwargs.get("proxy", None), File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_portalpy.py", line 180, in __init__ proxy=kwargs.get("proxy", None), File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 234, in __init__ self._product = self._check_product() File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1932, in _check_product res = self.get(baseurl + "/info", params={"f": "json"}) File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 506, in get ignore_error_key=ignore_error_key, File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 625, in _handle_response self._handle_json_error(data["error"], errorcode) File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 648, in _handle_json_error raise Exception(errormessage) Exception: Your login session has been reset. Please try again. (Error Code: 404)

1 Reply
RhettZufelt
MVP Notable Contributor

I haven't published, and not federated, but does the ..... in the gis include the username/password?

 

gis = GIS(url='https://org.maps.arcgis.com/', username='AdminUsername', password='usersPassword')

 

R_

0 Kudos