Hello,
I have a secured geocoding service that is hosted on a stand alone arcgis server. And I am trying to use this service to batch geocode some data using ArcGIS API for python. However I am facing issues when trying to run the batch_geocode function.
Here is my code:
1) Importing the necessary libraries
(Note: Arcgis python API version installed is 2.1.0.3)
from arcgis.gis import gis
from arcgis.geocoding import Geocoder, get_geocoders, batch_geocode, geocode
2) Assigning the custom geocode service url and setting the preferred geocoder to custom_geocoder
custom_geocoder = "https://{servername}/arcgis/rest/services/NorthAmerica/GeocodeServer"
gis = GIS("http://www.arcgis.com", "username", "password")
esrinl_geocoder = Geocoder(nys_gcdr_url, gis)
esrinl_geocoder
3) output <Geocoder url : https:// "{custom_url}/arcgis/rest/services/NorthAmerica/GeocodeServer"
4) Random Addresses : ["REDWOOD AVE, MO / MELROSE ST, MO ( 42/B4 ), MODESTO","2504 DANA LN, MODESTO","1020 JAYHAWK WAY, MODESTO"]
5) results = batch_geocode(addresses, custom_geocoder)
6) Getting the following error:
Exception Traceback (most recent call last) File ~\.conda\envs\myenv\lib\site-packages\arcgis\gis\__init__.py:16903, in _GISResource._refresh(self) 16902 else: > 16903 dictdata = self._con.post( 16904 self.url, params 16905 ) # , token=self._lazy_token) 16906 except Exception as e: File ~\.conda\envs\myenv\lib\site-packages\arcgis\gis\_impl\_con\_connection.py:1557, in Connection.post(self, path, params, files, **kwargs) 1556 return resp -> 1557 return self._handle_response( 1558 resp=resp, 1559 out_path=out_path, 1560 file_name=file_name, 1561 try_json=try_json, 1562 force_bytes=kwargs.pop("force_bytes", False), 1563 ) File ~\.conda\envs\myenv\lib\site-packages\arcgis\gis\_impl\_con\_connection.py:1027, in Connection._handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key) 1024 errorcode = ( 1025 data["error"]["code"] if "code" in data["error"] else 0 1026 ) -> 1027 self._handle_json_error(data["error"], errorcode) 1028 return data File ~\.conda\envs\myenv\lib\site-packages\arcgis\gis\_impl\_con\_connection.py:1052, in Connection._handle_json_error(self, error, errorcode) 1049 errormessage = ( 1050 errormessage + "\n(Error Code: " + str(errorcode) + ")" 1051 ) -> 1052 raise Exception(errormessage) Exception: Token Required (Error Code: 499) During handling of the above exception, another exception occurred:
Need a way to solve this error. Any help would be appreciated.
Thank you!
Hey Vinnakota
It looks like an authentication issue. I would suggest sharing your geocoding service publicly and testing the notebook again as well as comparing your notebook with the following sample.
Hopefully that helps,
David