Search code examples
pythondjangogoogle-app-enginedjangoappengine

/_ah/queue/deferred strange import error


I have a django 1.5 running on Google App Engine using the djangoappengine module for the stitching. Everything works fine, except that about a half of the calls to /_ah/queue/deferred raise the following import error:

Traceback (most recent call last):
  File "..../third_party/djangoappengine/deferred/handler.py", line 2, in <module>
    from djangoappengine import main
ImportError: No module named djangoappengine

As you can see, the djangoappengine module sits inside the third_party directory, and this directory is added to sys.path in the appengine_config.py file, so there shouldn't be any problems doing from djangoappengine import main:

sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'third_party'))

The relevant line in app.yaml is:

handlers:
- url: /_ah/queue/deferred
  script: third_party/djangoappengine/deferred/handler.py
  login: admin

What is causing these sporadic import errors? Am I doing something wrong? Maybe there's an import loop I'm not aware of?


Solution

  • Found out that my code used old CGI interface instead of the newer WSGI. I Fixed this and the problem didn't return since.

    Updated app.yaml:

    handlers:
    - url: /_ah/queue/deferred
      script: djangoappengine.deferred.handler.application
      login: admin