AnsweredAssumed Answered

Python script to replicate an ArcGIS Online hosted feature service.

Question asked by jmward on Mar 24, 2016
Latest reply on Mar 28, 2016 by jmward

I am trying to replicate a hosted feature service in a local file geodatabase to do some local analysis.  I have found this code on GitHub that I have been trying to use.  I set it up according to the instructions and I get a KeyError on line 9 below:

 

crValues = {'f' : 'json',
  'layers' : '0',
  'returnAttachments' : 'true',
  'token' : token }
crData = urllib.urlencode(crValues)
crRequest = urllib2.Request(crUrl, crData)
crResponse = urllib2.urlopen(crRequest)
crJson = json.load(crResponse)
replicaUrl = crJson['URL']
urllib.urlretrieve(replicaUrl, 'myLayer.json')

 

Error screenshot:

I was able to run all of the commands in the IDLE interactive window successfully and check the results of each command.  There is no 'URL' key in the crJson dictionary.  Here are a list of the keys that are:

 

[u'supportsCalculate', u'editingInfo', u'typeIdField', u'supportsValidateSql', u'advancedQueryCapabilities', u'supportsCoordinatesQuantization', u'supportsRollbackOnFailureParameter', u'allowGeometryUpdates', u'globalIdField', u'supportsAdvancedQueries', u'id', u'relationships', u'drawingInfo', u'capabilities', u'indexes', u'currentVersion', u'geometryType', u'hasStaticData', u'type', u'useStandardizedQueries', u'supportedQueryFormats', u'isDataVersioned', u'supportsAttachmentsByUploadId', u'supportsApplyEditsWithGlobalIds', u'description', u'standardMaxRecordCount', u'defaultVisibility', u'extent', u'objectIdField', u'tileMaxRecordCount', u'htmlPopupType', u'types', u'hasM', u'displayField', u'name', u'templates', u'supportsStatistics', u'hasAttachments', u'fields', u'maxScale', u'copyrightText', u'hasZ', u'maxRecordCount', u'minScale', u'maxRecordCountFactor', u'editFieldsInfo', u'serviceItemId']

 

The code is over two years old, have there been changes to the way requests are handled?

 

Any thoughts?

 

Many thanks.

Outcomes