Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.9k stars 1.1k forks source link

Geocoding not working with ArcGIS Enterprise Portal #1108

Closed jrmatchett closed 3 years ago

jrmatchett commented 3 years ago

Describe the bug The geocode function produces an error when using an Enterprise Portal GIS object. Geocoding works fine with an ArcGIS Online GIS object.

To Reproduce Steps to reproduce the behavior:

from arcgis import GIS
from arcgis.geocoding import geocode

gis = GIS('https://maps.myenterprise.org/portal', client_id='XXXX')

geocode('380 New York St, Redlands, CA 92373')

error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/2j/yrfvl2bj1ld05s_r3gwk39yh0000gp/T/ipykernel_33164/2847291716.py in <module>
----> 1 geocode('380 New York St, Redlands, CA 92373')

~/opt/miniconda3/envs/arcgis191/lib/python3.8/site-packages/arcgis/geocoding/_functions.py in geocode(address, search_extent, location, distance, out_sr, category, out_fields, max_locations, magic_key, for_storage, geocoder, as_featureset, match_out_of_range, location_type, lang_code, source_country)
   1333     if geocoder is None:
   1334         geocoder = arcgis.env.active_gis._tools.geocoders[0]
-> 1335     return geocoder._geocode(
   1336         address,
   1337         search_extent,

~/opt/miniconda3/envs/arcgis191/lib/python3.8/site-packages/arcgis/geocoding/_functions.py in _geocode(self, address, search_extent, location, distance, out_sr, category, out_fields, max_locations, magic_key, for_storage, as_featureset, match_out_of_range, location_type, lang_code, source_country)
    223         if address is not None:
    224             if isinstance(address, str):
--> 225                 params[self._address_field] = address
    226             elif isinstance(address, dict):
    227                 params.update(address)

AttributeError: 'Geocoder' object has no attribute '_address_field'

Platform (please complete the following information):

jrmatchett commented 3 years ago

Digging into this a bit further, the Geocoder's _address_field isn't getting set because a token isn't being generated when attempting to retrieve its properties (in this case, it's an Enterprise Portal geocoding service that isn't publicly accessible). The root cause appears to be what I pointed out in this issue with the Connection.generate_portal_server_token method not handing oauth authentication.

achapkowski commented 3 years ago

@jrmatchett thank you for this information, it's very helpful. I'll add it to our board and take a look at this.

achapkowski commented 3 years ago

The issue is resolved in v2.0.0 of the Python API, which will come out in Q1 of 2022

thakkarsmit11 commented 11 months ago

Hi, I am having same issue. Is this issue resolved? December 2023