AnsweredAssumed Answered

How to generate token for ArcGIS Online/Python

Question asked by geoffreywestgis on Apr 23, 2015
Latest reply on Apr 28, 2015 by pfoppe

I would like to consume hosted features from ArcGIS Online into a local file geodatabase.  I am consistently receving a 498 error.  I am generating a token but when passing into ArcGIS server it is invalid.  A couple of questions.


a.) Do I need to use my organization url, i.e. for my referrer?

b.) When I am creating a replica; should this data be hosted in


I am making some changes to the script  linked below which I found on github that uses urllib2, it doesn't work and isn't as elegant as the Requests.  And for my purposes I do not need to add attachments to the database, just consume a table locally.


Python script to pull hosted features with attachments into a local file geodatabase. See ReadMe below.


Here are my script and results


url = ''
payload  = {'username' : 'myUser,
'password' : 'myPass!',
'referer' : '',
'f' : 'json' }

r =, data=payload)
token =json.loads (r.text)

aToken = token['token']

print aToken

# Create Replica ###
# Update service url HERE ###
url2 = 'http://myIP:6080/arcgis/rest/services/FeatureMapService/FeatureServer/CreateReplica'
# #
payload2 = {'f' : 'json',
'layers' : '1',
'returnAttachments' : 'false',
'token' : token }

r2 =, data=payload2)
repLoad = json.loads (r2.text)

print repLoad

C:\Python27\ArcGIS10.2\python.exe C:/Users/GIS/Documents/ArcGIS/
{u'error': {u'message': u'Invalid Token', u'code': 498, u'details': []}}