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. myorg.maps.arcgis.com for my referrer?

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

 

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 = 'https://www.arcgis.com/sharing/generateToken'
payload  = {'username' : 'myUser,
'password' : 'myPass!',
'referer' : 'www.arcgis.com',
'f' : 'json' }

r = requests.post(url, 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 = requests.post(url2, data=payload2)
repLoad = json.loads (r2.text)


print repLoad

C:\Python27\ArcGIS10.2\python.exe C:/Users/GIS/Documents/ArcGIS/timequery.py
lOg8435-zLN8aeWknNveul8EzYlmbKb2h5GXVHCazEEbs0VgvyKH-0rr-iZ3RNwN_HP0BfykxtuzgZaw_Bm8LMZoOoJ9KtydsLze2mEX5qcFKBKltW_goPIH9w43jvgtCqHGAbotdyGMTAZZ217QEVTNqnW74rgBtjf1eB7XFMUb1miuJbU2YhPDnpbQB1S-9alNOrp6loXtBzJFEN-oAA..
{u'error': {u'message': u'Invalid Token', u'code': 498, u'details': []}}

Outcomes