AppRegistryNotReady: Apps aren't loaded yet. Django - python

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?

You should first initiate django this way in your script:
import django
django.setup()
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..

In your script initiate django as:
from django_root_app.wsgi import application

Related

geodjango with mysql database

I am developing an application with geodjango and I have been running into some difficulties. following the procedures on the official django website https://docs.djangoproject.com/en/1.11/ref/contrib/gis/tutorial/#use-ogrinfo-to-examine-spatial-data . I first used the orginfo to check spatial data I got a failed message
FAILURE:
Unable to open datasource `world/data/TM_WORLD_BORDERS-0.3.shp' with the following drivers.
then I followed the remaining process creating the models and the error I got when I ran migration was
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/Olar/Desktop/arbithub/src/geolocation/models.py", line 5, in <module>
from django.contrib.gis.db import models
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
from django.contrib.gis.db.models.aggregates import * # NOQA
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/db/models/aggregates.py", line 1, in <module>
from django.contrib.gis.db.models.fields import ExtentField
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
from django.contrib.gis import forms, gdal
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
from .fields import ( # NOQA
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/forms/fields.py", line 4, in <module>
from django.contrib.gis.geos import GEOSException, GEOSGeometry
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/geos/__init__.py", line 18, in <module>
HAS_GEOS = geos_version_info()['version'] >= '3.3.0'
File "/Users/Olar/Desktop/arbithub/lib/python2.7/site-packages/django/contrib/gis/geos/libgeos.py", line 196, in geos_version_info
raise GEOSException('Could not parse version info string "%s"' % ver)
django.contrib.gis.geos.error.GEOSException: Could not parse version info string "3.6.2-CAPI-1.10.2 4d2925d6"
.
further codes would b supplied based on request. Kindly help with it
The Could not parse version info string error is the issue in ticket 28441, which has been fixed in Django 1.11.5.
Note that it's always a good idea to use the latest point release (currently 1.11.5 for 1.11.X) to make sure you've got the latest security patches and bug fixes.

Scrapyd, Celery and Django running with Supervisor - GenericHTTPChannellProtocol Error

I'm using a project called Django Dynamic Scraper to build a basic web scraper on top of Django. Everything works find in development but when setting up on my Digital Ocean VPS I run into issues.
I'm using Supervisor to keep three things running:
Scrapyd on 0.0.0.0:6800
Celery task scheduler
Celery worker
Whenever Celery passes a job to Scrapyd to scrape I get an error logged to the Scrapyd log:
2017-08-29T08:49:06+0000 [twisted.python.log#info] "127.0.0.1" - - [29/Aug/2017:08:49:05 +0000] "POST /schedule.json HTTP/1.1" 200 3464 "-" "-"
2017-08-29T08:49:07+0000 [_GenericHTTPChannelProtocol,5,127.0.0.1] Unhandled Error
Traceback (most recent call last):
File "/home/dean/website/venv/local/lib/python2.7/site-packages/twisted/web/http.py", line 2059, in allContentReceived
req.requestReceived(command, path, version)
File "/home/dean/website/venv/local/lib/python2.7/site-packages/twisted/web/http.py", line 869, in requestReceived
self.process()
File "/home/dean/website/venv/local/lib/python2.7/site-packages/twisted/web/server.py", line 184, in process
self.render(resrc)
File "/home/dean/website/venv/local/lib/python2.7/site-packages/twisted/web/server.py", line 235, in render
body = resrc.render(self)
--- <exception caught here> ---
File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapyd/webservice.py", line 21, in render
return JsonResource.render(self, txrequest).encode('utf-8')
File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapyd/utils.py", line 20, in render
r = resource.Resource.render(self, txrequest)
File "/home/dean/website/venv/local/lib/python2.7/site-packages/twisted/web/resource.py", line 250, in render
return m(request)
File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapyd/webservice.py", line 49, in render_POST
spiders = get_spider_list(project, version=version)
File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapyd/utils.py", line 137, in get_spider_list
raise RuntimeError(msg.encode('unicode_escape') if six.PY2 else msg)
exceptions.RuntimeError: Traceback (most recent call last):\n File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main\n "__main__", fname, loader, pkg_name)\n File "/usr/lib/python2.7/runpy.py", line 72, in _run_code\n exec code in run_globals\n File "/home/dean/website/venv/lib/python2.7/site-packages/scrapyd/runner.py", line 40, in <module>\n main()\n File "/home/dean/website/venv/lib/python2.7/site-packages/scrapyd/runner.py", line 37, in main\n execute()\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 148, in execute\n cmd.crawler_process = CrawlerProcess(settings)\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapy/crawler.py", line 243, in __init__\n super(CrawlerProcess, self).__init__(settings)\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapy/crawler.py", line 134, in __init__\n self.spider_loader = _get_spider_loader(settings)\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapy/crawler.py", line 330, in _get_spider_loader\n return loader_cls.from_settings(settings.frozencopy())\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapy/spiderloader.py", line 61, in from_settings\n return cls(settings)\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapy/spiderloader.py", line 25, in __init__\n self._load_all_spiders()\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapy/spiderloader.py", line 47, in _load_all_spiders\n for module in walk_modules(name):\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/scrapy/utils/misc.py", line 71, in walk_modules\n submod = import_module(fullpath)\n File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module\n __import__(name)\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/dynamic_scraper/spiders/checker_test.py", line 9, in <module>\n from dynamic_scraper.spiders.django_base_spider import DjangoBaseSpider\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/dynamic_scraper/spiders/django_base_spider.py", line 13, in <module>\n django.setup()\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/django/__init__.py", line 22, in setup\n configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__\n self._setup(name)\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup\n self._wrapped = Settings(settings_module)\n File "/home/dean/website/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__\n mod = importlib.import_module(self.SETTINGS_MODULE)\n File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module\n __import__(name)\nImportError: No module named IG_Tracker.settings\n
On the final line of the stacktrace it seems to be having trouble importing my Django project settings into the scrapy project settings. My scrapy project is located inside one of my Django apps as recommended by Django Dynamic Scraper.
Here is my Scrapy settings file where it tries to import Django Settings (and succeeds in development):
import os
import sys
sys.path.append('../../../IG_Tracker/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'IG_Tracker.settings'
My Scrapyd Supervisor config:
[program:scrapyd]
directory=//home/dean/website/instagram/ig_scraper
command=/home/dean/website/venv/bin/scrapyd -n
environment=MY_SETTINGS=/home/dean/website/IG_Tracker/settings.py
user=dean
autostart=true
autorestart=true
redirect_stderr=true
numprocs=1
stdout_logfile=/home/dean/website/scrapyd.log
stderr_logfile=/home/dean/website/scrapyd.log
startsecs=10

AttributeError: 'Settings' object has no attribute 'OSCAR_REQUIRED_ADDRESS_FIELDS'

i have this issue in django oscar when i execute python manage.py migrate i am a beginner in django oscar .any help and suggestions are welcome.
below is my error message.
#localhost production1]$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/usr/lib64/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib64/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/usr/lib64/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/lib/python2.7/site-packages/oscar/apps/address/models.py", line 1, in <module>
from oscar.apps.address.abstract_models import (
File "/usr/lib/python2.7/site-packages/oscar/apps/address/abstract_models.py", line 19, in <module>
class AbstractAddress(models.Model):
File "/usr/lib/python2.7/site-packages/oscar/apps/address/abstract_models.py", line 35, in AbstractAddress
POSTCODE_REQUIRED = 'postcode' in settings.OSCAR_REQUIRED_ADDRESS_FIELDS
File "/usr/lib64/python2.7/site-packages/django/conf/__init__.py", line 57, in __getattr__
val = getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'OSCAR_REQUIRED_ADDRESS_FIELDS'
by docs
The last addition to the settings file is to import all of Oscar’s default settings:
from oscar.defaults import *
more details install-by-hand, hope it help you

500 Server Error on GAE - MySQLdb not loaded

I get a 500 Server Error while uploading my app on GAE. It works perfectly fine locally with dev_appserver with SETTINGS_MODE='prod'.
Based on the logs, it cannot find MySQLdb on GAE. It does not make sense to me.
Help!
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/core/handlers/wsgi.py", line 236, in __call__
self.load_middleware()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/core/handlers/base.py", line 49, in load_middleware
mod = import_module(mw_module)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/contrib/auth/middleware.py", line 3, in <module>
from django.contrib.auth.backends import RemoteUserBackend
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/contrib/auth/backends.py", line 3, in <module>
from django.contrib.auth.models import Permission
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/contrib/auth/models.py", line 8, in <module>
from django.db import models
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/db/utils.py", line 27, in load_backend
return import_module('.base', backend_name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5/django/db/backends/mysql/base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
The answer is fairly simple. Add the following lines in the app.yaml file:
libraries:
- name: MySQLdb
version: "latest"
Details can be found on the page
https://cloud.google.com/appengine/docs/python/cloud-sql

Django migration

I have migrated django website from live server to my localhost, i took the backup of posrgresql database and attached to my localhost i have changed the databse connection details in the live_setting.py and also installed the required packages which were already installed on the live server but i am unable to run the website on my localhost when i use manage.py ruserver command i got the following errors.
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x02BB6530>>
Traceback (most recent call last):
File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 91, in inner_run self.validate(display_num_errors=True)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 266,in validate num_errors = get_validation_errors(s, app)
File "C:\Python26\lib\site-packages\django\core\management\validation.py", line 30, in get_validation_errors for (app_name, error) in get_app_errors().items():
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 158, inget_app_errors self._populate()
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 67, in_populate self.load_app(app_name)
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 88, in load_app models = import_module('.models', app_name)
File "C:\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module__import__(name)
File "C:\Python26\lib\site-packages\django_social_auth3-0.7.20-py2.6.egg\social_auth\models.py", line 8, in <module>'social_auth.db.django_models'))
File "C:\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module__import__(name)
File "C:\Python26\lib\site-packages\django_social_auth3-0.7.20-py2.6.egg\social_auth\db\django_models.py", line 5, in <module>from social_auth.db.base import UserSocialAuthMixin, AssociationMixin, \
File "C:\Python26\lib\site-packages\django_social_auth3-0.7.20-py2.6.egg\social_auth\db\base.py", line 7, in <module> from openid.association import Association as OIDAssociation
File "build\bdist.win32\egg\openid\association.py", line 37, in <module>
File "build\bdist.win32\egg\openid\cryptutil.py", line 33, in <module>
File "build\bdist.win32\egg\openid\oidutil.py", line 16, in <module> ImportError: No module named parse
I am using python 2.6 and django 1.4.3, how can i solve these errors, i am new to python/django development.

Categories

Resources