I am getting the following error with connecting to ArcGIS Server 10.4 using the arcgis python api 1.6.2 with python 3.6.6:
UnboundLocalError: local variable 'resp' referenced before assignmentIs there a fix for this issue?
This issue is with the ArcGIS API for Python 1.6.1+. It appears that portalpy.py was only tested against AGOL and Portal not test ArcGIS Server. I created a python clone using ArcGIS Pro and was able to make a few modification to get it working for 1.6.1.. I could send you my portalpy.py and connection.py modules with my changes.
The main issue is with ...\impl\portalpy.py.
In the Portal class __init__ I added an additional check (lines 114 & 115) to check the url for an ArcGIS server and replaced line 118 (commented out) with line 117. Line 118 is the main issue - if none of the url strings are found it just assumes it's a Portal url.
I also added an additional check (see below screen capture) to check the url for an ArcGIS Server "/arcgis/rest/" style url. I had to do this because the "all_ssl" parameter needed to be False in my case. Again this whole block between 139 and 182 (note comment on 139) just assumed we're connecting to AGOL or Portal. My added lines 154-168 using the normalized_url are a total hack because self._is_arcpy (line 140) only allows 2 options.
I also had to inject a couple of lines in the get_properties function (lines 1095- 1097) to support a 'SERVER' connection with no ssl or token.
I made a modification to ...\impl\connection.py to include support for a server (lines 650 - 651)
Finally there was one minor modification required in ...\gis\__init__.py (lines 451-453). There is a product version check for portal but this throws an error for server. Again this code assumes your only connecting to AGOL or Portal. The weird thing is _product_version is never used anywhere in the code so commenting it out has no impact.
If you implement these modification in your clone you'll need to call GIS including the "verify_cert=False"
_gis_server = GIS(_service_url, _user_name, _pass_word, verify_cert=False)
Don't forget that you'll need to run your script using your clone
Hope this helps someone - Allen
Retrieving data ...