geocode_addresses() does not reference enterprise geocode server when directed to

166
4
a week ago
Labels (2)
mmalloy
Emerging Contributor

Am using a simple script to geocode a dataframe of addresses in R using my organization's enterprise geocoding server, but am getting an error indicating that my request is being directed to the default ArcGIS World Geocode Server and the request fails. Code is below, and was working as recently as this past March. I am successfully generating a token and connecting to the enterprise geocode server, all metadata appears in my environment, but the `geocode_addresses()` job fails. 

library(arcgisutils)
library(arcgisgeocode)
library(dplyr)

arcgis_token <- arcgisutils::auth_code()  ## complete OAuth2 in browser, get code

print(arcgis_token)  ## confirm correct

set_arc_token(arcgis_token) ## set token as default

test <- tribble(~name, ~addr, ~id,
                "info", "for", "testaddresses")

gc <- geocode_server("<enterprise server address>")

results <- geocode_addresses(
                            single_line = test$addr,
                            for_storage = FALSE,
                            geocoder = gc
                                    )

 

And then I get the following error + traceback:

<error/rlang_error>
Error in `geocode_server()`:
! Status code: 498
Error: Invalid Token
---
Backtrace:
 1. └─arcgisgeocode::geocode_addresses(...)
 2.   └─arcgisgeocode:::has_custom_fields(geocoder)
 3.     └─arcgisgeocode::world_geocoder()
 4.       └─arcgisgeocode::geocode_server("https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer")

 

Additional notes: 

- My ArcGIS server admin is stumped helping me troubleshoot this, as he does see my request against our enterprise server in his server log. 
-  If I run list_geocoders() after assigning my enterprise server to variable gc, I only see the ArcGIS World geocode server listed
- If I run default_geocoder(<my_token>), I get the error below:

<error/rlang_error>
Error in `geocode_server()`:
! Status code: 498
Error: Invalid Token
---
Backtrace:
 1. └─arcgisgeocode::default_geocoder(arcgis_token)
 2.   └─arcgisgeocode::geocode_server(res[1, "url"])
 3.     └─arcgisutils::detect_errors(res)
 4.       └─rlang::abort(e_msg, call = error_call)

Any ideas would be appreciated. We already spoke to our ESRI tech support contact and he said they can't help with R and directed me here. 

ARCGIS_CLIENT and ARCGIS_HOST are saved in my .REnviron. Using R 4.5.1 (also tried this in 4.3.3 and did not work) in RStudio IDE version 2025.05.1+513

0 Kudos
4 Replies
KevinBoes2
Emerging Contributor

Maybe you've already checked for this, but since it came up for me while I was working on a similar workflow, does the geocode_addresses() function get run pretty soon after the token is set? I found while I was writing my script that enough time had passed since I'd set the token that it timed out, and the script ran as expected after resetting the token.

0 Kudos
mmalloy
Emerging Contributor

Yes, I am running geocode_addresses() almost immediately after setting the token. Our tokens expire after 30 minutes so I do it quickly. 

0 Kudos
KevinBoes2
Emerging Contributor

That's good. For my script, I connected to the enterprise geocoding service by retrieving the url from the list returned by the list_geocoders() function. You mentioned that when you run that function, you don't see your enterprise geocoder in that list; I wonder if the issue is stemming from the fact that the geocoder isn't visible to you.

I also included my token in the geocode_addresses() function with the token parameter, though I think that might be redundant.

0 Kudos
mmalloy
Emerging Contributor

Yeah I never tried running list_geocoders() before experiencing this issue because it ran just fine from the server URL. I assume it showed up then. 

I forgot to mention but I did try it with the token argument entered too, still didn't work. 

Appreciate the suggestions!

0 Kudos