"import json" error with python-written robot

27 views
Skip to first unread message

Niall

unread,
Nov 3, 2009, 3:19:13 PM11/3/09
to Google Wave API
Hi,

I am currently writing a google wave robot for kicks, and I get the
following error:


<type 'exceptions.ImportError'>: No module named json
Traceback (most recent call last):
File "/base/data/home/apps/myWaveRobot/1.337487432489076904/
myWaveRobot.py", line 14, in <module>
import myWaveRobotModule
File "/base/data/home/apps/myWaveRobot/1.337487432489076904/
myWaveRobotModule.py", line 3, in <module>
import json


And line three of myWaveRobotModule.py is --


import json


I did some searching and I can't figure out why I'm getting that error
and couldn't see anything that seemed to match my problems. The error
is printed like 19 times in the appenging main logs, but I don't know
if that's important.

Can anyone tell me why json doesn't work?

Thanks. Let me know if you need any more information.

Niall

unread,
Nov 3, 2009, 5:32:36 PM11/3/09
to Google Wave API
OK. I figured it out. I did a version check on python on wave and got:

2.5.2 (r252:60911, Apr 7 2009, 17:42:26)
[GCC 4.1.0]

And if I remember right json came in with 2.6.

Holger

unread,
Nov 3, 2009, 4:19:26 PM11/3/09
to Google Wave API
try this:

from django.utils import simplejson as json

had the same problem

Lee

unread,
Nov 3, 2009, 4:57:31 PM11/3/09
to Google Wave API
Hi, the JSON library within python is native only for version 2.6.x
and up, try the following

easy_install simplejson - Make sure that you have installed ez_setup

and within myWaveRobotModule.py, replace import json with import
simplejson

The two libraries' methods use the same method names and the same set
of parameters so there shouldn't be any compatibility issue.

Niall

unread,
Nov 4, 2009, 9:42:55 AM11/4/09
to Google Wave API
Cheers.
I got it working before I saw the solutions ye posted. I went to
http://pypi.python.org/pypi/simplejson/2.0.9 and downloaded simplejson
and uploaded it with the robot I'm using. I might try to use Holger's
solution, though.
Thanks.

Now, my robot works does basically what it should do, but I'd like to
make it confugurable and I think the best way to do that would be to
allow whover's using the robot to select options from a dropdown menu
(from a blip that the robot posts when it is added to a wave). I've
seen this from a few different robots, but I'm not sure how it was
done. I've seen it on a few robots (aunt-rosie, for example, but
that's written in Java) so I figure it might be possible with python.
I searched, as i said. But couldn't see much that looked useful.

Cheers.

Lee

unread,
Nov 4, 2009, 5:39:30 PM11/4/09
to Google Wave API
The beauty of API design, and this is especially true of Google
projects, is that the binding exposes the same sets of methods and
objects for every language that it supports, so in theory it should be
relatively easy to port specific portions of the app across different
languages (all you need is a the most rudimentary amount of knowledge
about the syntax of Java).

If you can provide the link to download for the aunt-rosie robot, I
can help you locate and port the code to python. (Although it may be
in the API document, make sure that you check there first).

On 4 Nov, 08:42, Niall <twom...@gmail.com> wrote:
> Cheers.
> I got it working before I saw the solutions ye posted. I went tohttp://pypi.python.org/pypi/simplejson/2.0.9and downloaded simplejson

Niall

unread,
Nov 4, 2009, 6:14:14 PM11/4/09
to Google Wave API
Thanks for your reply, Lee.
I don't think the code for aunt-rosie is available (aunt-
ro...@appspot.com to use it, and the developer's website is here
http://andrewhitchcock.org/?post=322)

I think I know what I have to do, though. I was looking at the row of
four source code, so I think I have to make a bit of a module like
what it's got here http://rowoffour.appspot.com/gadget.xml
I'll go play around with this for a while and report back with
successes and failures.

Lee

unread,
Nov 4, 2009, 7:52:12 PM11/4/09
to Google Wave API
Looking at the API, the following python object will allow you to
create a local UI on the client browser

waveapi.document.Gadget(resource)

And

blip.GetDocument().AppendElement(Element*)

Subclassed instances of Element are also allowed, so you can initiate
a document.Gadget object

The wave environment already provides an interface for the host
application (more info at http://code.google.com/apis/wave/extensions/gadgets/guide.html),
the following might help

The gadget will contain a list that automatically invokes wave.getState
().submitDelta(dict); everytime the change event occurs on the list
(you can do this via jQuery) and the result is sent back to the
application, which does what it needs off of the information.

On 4 Nov, 17:14, Niall <twom...@gmail.com> wrote:
> Thanks for your reply, Lee.
> I don't think the code for aunt-rosie is available (aunt-
> ro...@appspot.com to use it, and the developer's website is herehttp://andrewhitchcock.org/?post=322)
>
> I think I know what I have to do, though. I was looking at the row of
> four source code, so I think I have to make a bit of a module like
> what it's got herehttp://rowoffour.appspot.com/gadget.xml

Niall

unread,
Nov 7, 2009, 9:15:22 AM11/7/09
to Google Wave API
Thanks for your reply, Lee. I've been working on and off over the last
couple of days and I think I'm stuck.

The code I'm using can be found here --
http://code.google.com/p/googlewaverobots/source/browse/trunk/robottestwave/robottestwave.py
and the gadget is found here
http://code.google.com/p/googlewaverobots/source/browse/trunk/robottestwave/public/dropdown.xml

(I decided to try to replicate the translation robot, as it seemed
like it'd teach me a good amount about python and the APIs)

Anyway, the problem I'm having is that I can't get the robot, when a
new blip is submitted, to read the state of the gadget, but when I
modify the languages in the dropdown options it gets them fine. I
think the problem is in how I search for the gadget, as when I modify
the state of the gadget it works well, but if I don't it doesn't find
the gadget.

I searched the groups and can't find a way of doing this that works
for me. I tried making global variables so that when the gadget is
modified the language pairs would likewise be modified. I made two
variables fr and to (language from which and to which we're
translating) and in the onBlipSubmitted I did a global fr and global
to and tried modifying them in the gadget key, elem gadget loop but to
no avail -- I got no errors, but it wouldn't modify the values for me.
You can also see what I've tried on the previous revisions of the
code. If I set a default value for the global variables I can't change
it, and if I don't set anything it says that the global name is not
defined.

Any help is very much appreciated.

Cheers.




On Nov 5, 12:52 am, Lee <leeyuan...@gmail.com> wrote:
> Looking at the API, the following python object will allow you to
> create a local UI on the client browser
>
> waveapi.document.Gadget(resource)
>
> And
>
> blip.GetDocument().AppendElement(Element*)
>
> Subclassed instances of Element are also allowed, so you can initiate
> a document.Gadget object
>
> The wave environment already provides an interface for the host
> application (more info athttp://code.google.com/apis/wave/extensions/gadgets/guide.html),

Niall

unread,
Nov 7, 2009, 10:51:15 AM11/7/09
to Google Wave API
I realised my code was fine so that it was probably a problem with
globals, and found out that you can't use them here, or at least that
they can't be modified.
So I used the datastore, and it works now, which is nice.

Working solution can be found on the links I provided above.

On Nov 7, 2:15 pm, Niall <twom...@gmail.com> wrote:
> Thanks for your reply, Lee. I've been working on and off over the last
> couple of days and I think I'm stuck.
>
> The code I'm using can be found here --http://code.google.com/p/googlewaverobots/source/browse/trunk/robotte...
> and the gadget is found herehttp://code.google.com/p/googlewaverobots/source/browse/trunk/robotte...

Lee

unread,
Nov 8, 2009, 11:18:01 PM11/8/09
to Google Wave API
That's strange, revision 24
http://code.google.com/p/googlewaverobots/source/diff?path=/trunk/robottestwave/robottestwave.py&format=side&r=24&old_path=/trunk/robottestwave/robottestwave.py&old=23,
should theoretically have worked unless the code was executed in a
discrete manner (IE: the state isn't continuous).

Also, a maybe useful tool in the future

http://gist.github.com/229682

Basically a decorator factory that can let you add in handlers on the
fly. (Note I haven't tested this yet so it may be prudent to tread the
waters carefully) It felt like a more intuitive approach than the
instance.RegisterHandler(*args) approach
Reply all
Reply to author
Forward
0 new messages