pombreda / wave-robot-python-client

Automatically exported from code.google.com/p/wave-robot-python-client
Apache License 2.0
0 stars 0 forks source link

Unable to parse json body of incoming message #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I am seeing this frequently since yesterday (2009-08-05). This appears 
in the appengine log:

'NoneType' object has no attribute 'get'
Traceback (most recent call last):
  File 
"/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 
509, in __call__
    handler.post(*groups)
  File "/base/data/home/apps/lab2market/3.335431291113361462/api/robot.py", 
line 88, in post
    context, events = robot_abstract.ParseJSONBody(json_body)
  File 
"/base/data/home/apps/lab2market/3.335431291113361462/api/robot_abstract.py
", line 37, in ParseJSONBody
    context = ops.CreateContext(data)
  File "/base/data/home/apps/lab2market/3.335431291113361462/api/ops.py", 
line 580, in CreateContext
    context.AddWavelet(data['wavelet'])
  File "/base/data/home/apps/lab2market/3.335431291113361462/api/ops.py", 
line 521, in AddWavelet
    wavelet = OpBasedWavelet(wavelet_data, self)
  File "/base/data/home/apps/lab2market/3.335431291113361462/api/ops.py", 
line 126, in __init__
    super(OpBasedWavelet, self).__init__(json)
  File "/base/data/home/apps/lab2market/3.335431291113361462/api/model.py", 
line 90, in __init__
    self.creator = json.get('creator','')
AttributeError: 'NoneType' object has no attribute 'get'

Here is the incoming json_body:
{"blips":{"map":{},"javaClass":"java.util.HashMap"},"events":{"javaClass":"
java.util.ArrayList","list":[]},"wavelet":null}

How to reproduce:
In [7]: import robot_abstract
In [7]: jsonbody = 
'{"blips":{"map":{},"javaClass":"java.util.HashMap"},"events":{"javaClass":
"java.util.ArrayList","list":[]},"wavelet":null}'
In [7]: robot_abstract.ParseJSONBody(json_body)                                 

What is the expected output? What do you see instead?
It is supposed to return context and event object, but throws up an error:
/home/spacefra/projects/wave/nokar/api/model.py in __init__(self, json)
     88       json: JSON data from Wave server.
     89     """
---> 90     self.creator = json.get('creator')
     91     self.creationTime = json.get('creationTime', 0)
     92     self.dataDocuments = json.get('dataDocuments', {})

AttributeError: 'NoneType' object has no attribute 'get'

What version of the product are you using? On what operating system?
svn r11 of wave-robot-python-client

Please provide any additional information below.
I think the server is sending spurious data without the fields properly 
specified, but the client needs to handle it gracefully.

Original issue reported on code.google.com by chakra...@gmail.com on 6 Aug 2009 at 5:32

GoogleCodeExporter commented 9 years ago
The following patch seems to be stopping the exception flow:

--- a/api/ops.py        Thu Aug 06 10:51:31 2009 -0700
+++ b/api/ops.py        Fri Aug 07 12:45:42 2009 -0700
@@ -577,7 +577,8 @@
     context.AddBlip(raw_blip_data)

   # Currently only one wavelet is sent.
-  context.AddWavelet(data['wavelet'])
+  if data['wavelet']:
+      context.AddWavelet(data['wavelet'])

   # Waves are not sent over the wire, but we can build the list based on the
   # wave ids of the wavelets.

Original comment by chakra...@gmail.com on 7 Aug 2009 at 7:46

GoogleCodeExporter commented 9 years ago
Some more information:

This incoming data comes only when I was toying with the RegisterCronJob() 
interface of 
the robot. In that case, it seems like a bug, because it is not hitting the 
correct URL 
which I specified in the RegisterCronJob() function and the data is all blanks. 
Please 
inform how to use this interface.

Original comment by chakra...@gmail.com on 7 Aug 2009 at 8:30

GoogleCodeExporter commented 9 years ago
Hey keep up the great work nice

Original comment by jesuschr...@gmail.com on 10 Aug 2009 at 9:09