json_node is list object not dictonary object
Closed this issue · 7 comments
GoogleCodeExporter commented
Sometimes json_node object is a list type and not a dictionary therefore it has
no attribute 'iteritems'
Original issue reported on code.google.com by aa...@aaronmdrake.com
on 2 May 2012 at 6:02
Attachments:
GoogleCodeExporter commented
can expand a little more on your description? i don't understand what the
issue is.
Original comment by jahlborn@gmail.com
on 3 May 2012 at 3:21
GoogleCodeExporter commented
Yea, the error message is:
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 703, in __call__
handler.post(*groups)
File "/Users/user/PROJECTS/gaerest/rest.py", line 1442, in post
self.post_impl()
File "/Users/user/PROJECTS/gaerest/rest.py", line 1459, in post_impl
self.update_impl(path, model_name, model_key, "POST", False)
File "/Users/user/PROJECTS/gaerest/rest.py", line 1484, in update_impl
doc = self.input_to_xml()
File "/Users/user/PROJECTS/gaerest/rest.py", line 1698, in input_to_xml
return json_to_xml(self.request.body_file)
File "/Users/user/PROJECTS/gaerest/rest.py", line 373, in json_to_xml
json_node_to_xml(xml_doc.documentElement, json_node[doc_el_name])
File "/Users/user/PROJECTS/gaerest/rest.py", line 382, in json_node_to_xml
for json_node_name, json_node_value in json_node.iteritems():
AttributeError: 'list' object has no attribute 'iteritems'
I create the JSON string from the javascript object like in the example. Then I
use jquery to POST the JSON data to the rest application. This is the error.
The problem is that the "json_node" in the source code is a list and not a
dictionary. So it will have to be copied to a dictionary or somehow cast as a
dictionary.
Original comment by aa...@aaronmdrake.com
on 3 May 2012 at 3:51
GoogleCodeExporter commented
what does your model look like.
Original comment by jahlborn@gmail.com
on 3 May 2012 at 4:08
GoogleCodeExporter commented
class NavigationTiming(polymodel.PolyModel):
unloadEventStart = db.IntegerProperty()
unloadEventEnd = db.IntegerProperty()
redirectStart = db.IntegerProperty()
redirectEnd = db.IntegerProperty()
fetchStart = db.IntegerProperty()
domainLookupStart = db.IntegerProperty()
domainLookupEnd = db.IntegerProperty()
connectStart = db.IntegerProperty()
connectEnd = db.IntegerProperty()
secureConnectionStart = db.IntegerProperty()
requestStart = db.IntegerProperty()
responseStart = db.IntegerProperty()
responseEnd = db.IntegerProperty()
domLoading = db.IntegerProperty()
domInteractive = db.IntegerProperty()
domContentLoadedEventStart = db.IntegerProperty()
domContentLoadedEventEnd = db.IntegerProperty()
domComplete = db.IntegerProperty()
loadEventStart = db.IntegerProperty()
loadEventEnd = db.IntegerProperty()
class BrowserPerformanceData(NavigationTiming):
createdate = db.DateTimeProperty(auto_now_add=True)
sessid = db.StringProperty()
url = db.URLProperty()
loadtime = db.IntegerProperty()
browser = db.StringProperty()
useragent = db.TextProperty()
Original comment by drak...@gmail.com
on 3 May 2012 at 4:09
GoogleCodeExporter commented
Perhaps another question would be how do I design the model such that the XML
looks like this:
<BrowserPerformanceData>
<createdate></createdate>
<sessid></sessid>
<url></url>
...
<NavigationTiming>
<unloadEventStart></unloadEventStart>
<unloadEventEnd></unloadEventEnd>
....
</NavigationTiming>
</BrowserPerformanceData>
Original comment by drak...@gmail.com
on 3 May 2012 at 4:13
GoogleCodeExporter commented
Here is a fix that worked:
...snip...
def json_node_to_xml(xml_node, json_node):
if (isinstance(json_node, list)):
json_node = json_node[0]
doc = xml_node.ownerDocument
...snip...
Original comment by aa...@aaronmdrake.com
on 4 May 2012 at 3:55
GoogleCodeExporter commented
You json object is incorrectly formed, which is causing the error. if you want
to be able to post multiple objects, then you can use the form:
{'list': {'BrowserPerformanceData': [{ ... }]}}
If you only want to post a single object, then you can use the form:
{'BrowserPerformanceData': { ... }}
(note the lack of inner square braces).
Original comment by jahlborn@gmail.com
on 15 May 2012 at 1:49
- Changed state: Invalid