views:

459

answers:

1

I'm trying to use app-engine-patch with pyamf by following this: http://pyamf.org/wiki/GoogleAppEngine because I want to migrate my Django <-> pyamf application to app-engine-patch <-> pyamf.

What I have now is that I created my gateway.py with only one line of code:

import pyamf

just to test can I use pyamf and I get blank page when I point my browser to that url/file so that looks good (no import problems and pyamf is found) but in the command prompt where I started server with "manage.py runserver" I see bunch of errors like:

...
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2238, in Dispatch
    self._module_dict)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2156, in ExecuteCGI
    reset_modules = exec_script(handler_path, cgi_path, hook)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2052, in ExecuteOrImportScript
    exec module_code in script_module.__dict__
  File "C:\Users\[my app-engine-patch application path]\common\appenginepatch\main.py", line 16, in <module>
    patch_all()
  File "C:\Users\[my app-engine-patch application path]\common\appenginepatch\appenginepatcher\patch.py", line 29, in patch_all
    patch_app_engine()
  File "C:\Users\[my app-engine-patch application path]\common\appenginepatch\appenginepatcher\patch.py", line 193, in patch_app_engine
    from django.utils.encoding import force_unicode, smart_str
ImportError: No module named encoding

Are there any pyamf <-> app-engine-patch gurus out there which can give me a hint what am I doing wrong and how can I setup pyamf to work with app-engine-patch?

+1  A: 

Are you activating Django 1.0.2 in your app engine startup code? App Engine now comes with it, but also (for backwards compatibility) with 0.9.6, and (still for backwards compatibility) 0.9.6 is what it defaults to -- all it takes to fix this is, at startup, use:

from google.appengine.dist import use_library
use_library('django', '1.0')

and then "Subsequent attempts to import the django package will use Django 1.0.2.". You do need to install 1.0.2 with the SDK separately. See all instructions here.

Alex Martelli
I don't use App engine Django, I use app-engine-patch which comes with zipped Django in the same package. Default app and my models are working *until* I enable pyamf. As soon as I do import pyamf I get errors "No module named encoding"
Perica Zivkovic
So it looks like pyamf must do some tricks with sys.path or other aspects of importing that are tripping up app-engine-patch's own tricks in the matter. What happens if you ensure that `sys.modules['django.utils.encoding']` is properly defined before you start pyamf (e.g. just `from django.utils import encoding` in your code where it still works before you start pyamf)? It's unlikely though not impossible that pyamf would remove entries from sys.modules so this might be a workaround worth trying!
Alex Martelli
You are a wise man Alex :-) from django.utils import encoding before pyamf calls works like a charm. Thanks for the help !!
Perica Zivkovic
You're welcome! I'm not sure exactly what import tricks pyamf is playing, but hardly any code ever goes to the bother of deleting entries already existing in sys.modules, which is why I was really hopeful that this trick would fix things;-).
Alex Martelli