Select to view content in your preferred language

urlencode list of dictionaries for applyEdits REST API

757
1
Jump to solution
01-19-2018 01:03 PM
danbecker
Frequent Contributor

featureList = [

   {

      'geometry': { 'y': 40.81670805699997, 'x': -96.71105736099997 },

      'attributes': { 'already_emailed': 'YES', 'objectid': 1, 'globalid': '{EEF86AC0-5B54-47E0-BFC8-496D457A6249}' }

   },

   {

      'geometry': { 'y': 40.816795984000066, 'x': -96.71107804500002 },

      'attributes': { 'already_emailed': 'YES', 'objectid': 2, 'globalid': '{723F5F66-98EE-4FE4-9075-31A476C60363}' }

    }

]

I have the above list of dictionaries. I'm trying to update these 2 features using the REST API, applyEdits.

I pasted the exact same list into the /applyEdits GUI on the REST endpoint and it was successful.

Here's the error the server is throwing, related to the brackets around globalid val.

Expected a ',' or '}' at character 138 of [{'geometry': {u'y': 40.81670805699997, u'x': -96.71105736099997}, 'attributes': {'already_emailed': 'YES', 'objectid': 1, 'globalid': u'{EEF86AC0-5B54-47E0-BFC8-496D457A6249}'}}, {'geometry': {u'y': 40.816795984000066, u'x': -96.71107804500002}, 'attributes':

Here's the method I'm using to urlencode

payload = {'updates': featureList,
                'token': accessToken,
               'useGlobalIds': 'true',
               'f': 'json'}
query_string = urllib.urlencode(payload)

req = urllib2.Request(url,query_string)

resp = urllib2.urlopen(req)

can someone help me urlencode that list of dictionaries?

thanks!

0 Kudos
1 Solution

Accepted Solutions
danbecker
Frequent Contributor

FYI: the solution is to convert to json string, then encode that

payload = {'updates': json.dumps(featureList),
                'token': accessToken,
               'useGlobalIds': 'true',
               'f': 'json'}
query_string = urllib.urlencode(payload)

req = urllib2.Request(url,query_string)

resp = urllib2.urlopen(req)

View solution in original post

1 Reply
danbecker
Frequent Contributor

FYI: the solution is to convert to json string, then encode that

payload = {'updates': json.dumps(featureList),
                'token': accessToken,
               'useGlobalIds': 'true',
               'f': 'json'}
query_string = urllib.urlencode(payload)

req = urllib2.Request(url,query_string)

resp = urllib2.urlopen(req)