AnsweredAssumed Answered

Python script to replicate hosted feature service on ArcGIS Online including attachments.

Question asked by jmward on Mar 28, 2016
Latest reply on Apr 1, 2016 by glosanders

I am trying to get this script to work for an application for one of our departments.  If you look at the comment by stuartalexandersanders in the GitHub link - that is the same error I am getting.  I'm hoping Alex Sanders is the same person and has fixed it?


gtUrl = ''
gtValues = {'username' : 'MyUsername',
  'password' : 'MyPassword',
  'referer' : '',
  'f' : 'json' }
gtData = urllib.urlencode(gtValues)
gtRequest = urllib2.Request(gtUrl, gtData)
gtResponse = urllib2.urlopen(gtRequest)
gtJson = json.load(gtResponse)
token = gtJson['token']

### Create Replica ###
### Update service url HERE ###
crUrl = ''


That code works and I am able to get a token for the feature service.


This next block is where I am having my trouble -


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')


The error I get is from the urlretrieve call.  myLayer.json is not a json file but an html file that says "Token Required".  The error text in python is:



Any ideas why this would happen?  Apparently it was working for Alex before the update to ArcGIS Online earlier this month.