Pass Token to World Geocode Service - Invalid Token

2826
2
10-22-2013 04:52 AM
KeithSandell
New Contributor III
Cross posting from ArcGIS Online forum at the recommendation of Esri.

I have to use python and the REST API to geocode records against the ArcGIS Online World Geocoding service.

I can successfully request a token, but when the token is passed as part of the geocode request I get an error message returned that it is invalid, with no other information. I've tried passing it as a url parameter and/or a header and both.

If I omit the the token and the forStorage parameter I can successfully obtain a response as expected, but I can't use this method because I need to store the results.

The server that the python script is running on is a VM in a Microsoft hosting environment. The token request requires the referring "website". In this case it is not a website, but a server so I am substituting the IP address of the server, assuming this is how the geocoding service is validating the geocode request. I've tried both the internal and external IP addresses, but neither have worked.

The docs recommend not using the REST API, but I have no choice in this case.

I need to know more about how the geocoding service is validating the token and how it interprets "websites" or in my case an ip address.

Any help would be much appreciated.
0 Kudos
2 Replies
RichardWatson
Frequent Contributor
A token consists of credentials, an expiration date, and a referer.  If the credentials are wrong then it will fail.  If the token is expired then it will fail.  If the referer is wrong then it will fail.  My guess is that the problem with the referer. 

I strongly recommend that you use a referer URL.  Just make one up, e.g. http:\\www.whatever.com.  After you do that then each request you make which uses the token has to add this URL to the request header.  I have wasted many hours trying to use the requestip option and it simply does not work reliably.  I did read your question and understood that you used an IP address.  I think that this gets complex because there are many ways to try and determine the IP address from a request but none of them work well.

Fiddler is your friend.
0 Kudos
AnttiKajanus1
Occasional Contributor III
+1 for rlwatson.

Couldn't agree more.
0 Kudos