I'm trying to run django 1.9 on google app engine. Got the below error when trying to access API's through Google API Explorer.
Traceback (most recent call last):
File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
__import__(cumulative_path)
File "/home/gemini/projects/cityguide-backend/src/cityguide/api/services.py", line 9, in <module>
from cityguide.api.internal.categories import Categories
File "/home/gemini/projects/cityguide-backend/src/cityguide/api/internal/categories.py", line 10, in <module>
from cityguide.models import Category
File "/home/gemini/projects/cityguide-backend/src/cityguide/models.py", line 8, in <module>
class ContactDetails(models.Model):
File "/home/gemini/projects/cityguide-backend/src/lib/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/gemini/projects/cityguide-backend/src/lib/django/apps/registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "/home/gemini/projects/cityguide-backend/src/lib/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
AppRegistryNotReady: Apps aren't loaded yet.
I already added
builtins:
- deferred: on
- remote_api: on
- django_wsgi: on
handlers:
- url: .*
script: mysite.wsgi.application
env_variables:
DJANGO_SETTINGS_MODULE: 'mysite.settings'
inside app.yaml
file.
wsgi.py
looks like
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
application = get_wsgi_application()
I tried adding django.setup()
line on the top of models.py
but it shows a different error.
ERROR 2016-02-01 10:03:02,918 wsgi.py:263]
Traceback (most recent call last):
File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
__import__(cumulative_path)
File "/home/gemini/projects/cityguide-backend/src/cityguide/api/services.py", line 9, in <module>
from cityguide.api.internal.categories import Categories
File "/home/gemini/projects/cityguide-backend/src/cityguide/api/internal/categories.py", line 10, in <module>
from cityguide.models import Category
File "/home/gemini/projects/cityguide-backend/src/cityguide/models.py", line 6, in <module>
django.setup()
File "/home/gemini/projects/cityguide-backend/src/lib/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/gemini/projects/cityguide-backend/src/lib/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/home/gemini/projects/cityguide-backend/src/lib/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/home/gemini/projects/cityguide-backend/src/lib/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/gemini/projects/cityguide-backend/src/lib/django/utils/module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/gemini/projects/cityguide-backend/src/cityguide/admin.py", line 2, in <module>
from cityguide.models import Category
ImportError: cannot import name Category
ERROR 2016-02-01 10:03:02,919 wsgi.py:263]
Traceback (most recent call last):
File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/home/gemini/softwares/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
__import__(cumulative_path)
File "/home/gemini/projects/cityguide-backend/src/cityguide/api/services.py", line 9, in <module>
from cityguide.api.internal.categories import Categories
File "/home/gemini/projects/cityguide-backend/src/cityguide/api/internal/categories.py", line 10, in <module>
INFO 2016-02-01 10:03:03,000 module.py:794] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 500 -
from cityguide.models import Category
INFO 2016-02-01 10:03:03,001 module.py:794] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 500 -
File "/home/gemini/projects/cityguide-backend/src/cityguide/models.py", line 6, in <module>
INFO 2016-02-01 10:03:03,001 module.py:794] default: "GET /_ah/api/discovery/v1/apis HTTP/1.1" 500 60
django.setup()
INFO 2016-02-01 10:03:03,001 module.py:794] default: "GET /_ah/api/discovery/v1/apis HTTP/1.1" 500 60
File "/home/gemini/projects/cityguide-backend/src/lib/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/gemini/projects/cityguide-backend/src/lib/django/apps/registry.py", line 78, in populate
raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant
Temporary solution for this problem:
Seems like I need to open the home page first. So that it would loads the db since I made the homepage to return all the db table contents . Once the db lists shown on the home page, we are ready to call the Google API Explorer.
Is there any way to refine this solution?
In your script initiate django as:
You should first initiate django this way in your script:
See https://docs.djangoproject.com/en/1.9/ref/applications/#django.setup
You can also look at the Troubleshooting section of the link to see other possibilities to solve this aprticular exception.
By adding the above two lines at the top of
services.py
file solves this problem for me..