friendfeed.py Patch for use on Google App Engine

Ask and ye shall receive.  Attached is a patch for using friendfeed.py on Google App Engine.  You need to also have demjson available.  Google App Engine does not allow use of many C modules (like cjson) and both json and simplejson will throw decoding errors from time to time. demjson is slow but won’t throw errors around (I really wish we could use cjson; it’s so much faster).

Basically the differences are:

  1. Use urlfetch instead of urllib2
  2. Use Django’s urlencode which will work with unicode (letting you comment/share in languages like Chinese)
  3. Use demjson instead of cjson (which cannot be used on Google App Engine), simplejson, or json (which both throw decoding errors from time to time)

Enjoy!

Update:

You don’t need to use demjson anymore; simplejson will work just fine.  I just got an email from Sanjeev saying that they fixed the issue (’\x’ is not valid JSON).  This makes things even easier because simplejson is included in Django (from django.utils import simplejson) which is included in Google App Engine.

Tags: , , , , ,

  • This is great! Thanks a lot. My own hacked up version was barely functional. :)
  • No problem; mine was hacky too for a long time. The thing that got me was urllib2 will automatically set the correct content-type when POSTing but urlfetch does not. I was stuck on that for hours.
  • Finally got some time to be playing around again - this worked great, I did update the json code to use django's simplejson (I was using that in my original crappy friendfeed.py :) - but other than that it was as you patched it and everything was smooth sailing.
  • Glad it's working for you; let me know if you have any trouble.
  • Great! This is something I've been waiting for. I hacked around it to get simple retrieval to work but I think I'll go ahead and replace my code with this.
  • Let me know how it works out for you.
  • abdellah
    HI,
    thank you very much for this patch, however, I got this error trying to use it:

    from django.utils import urlencode
    ImportError: cannot import name urlencode
  • Are you sure you have Django in your python path? You might also need to
    use Django trunk; I have not tested this using the version included in
    Google App Engine (which is .96 and very far away from trunk). This link (
    http://code.google.com/appengine/articles/djang...) tells you how to use
    trunk on GAE.

    Good luck!
  • abdellah
    Thank you very much, I too think that the problem come from Django, I tried using GAE SDK, without importing anything from Django, may I re-think about how to implement things in my project again.

    I havn't used Django as a framework before , even not think to associate it with GAE, for the moment I am trying webpy as a frame work.

    may be the solution is just to import the "django.utils.http import urlencode" I mean to include http to django utils in GAE.

    again thank you very much for your help and for the links.
  • abdellah
    HI, just to point that I found a tweak for my case , I mean a patch for non django framework users:

    1) download the following files :

    1-1)http
    1-2)encoding
    1-3)functional

    from :
    http://code.djangoproject.com/browser/django/br...

    adding those file to the project and it work, again thank you for this patch.
  • I should've taken the time to search before hacking my own version. Need to go back and apply your urlencode fix though. Thanks.

    http://adamloving.com/2008/07/22/changes-to-fri...
blog comments powered by Disqus