Django 1.5 with psycopg2 throw random errors - python

I faced with some strange problem. When I run single worker for my django application? like this:
python manage.py run_gunicorn -w 1
python manage.py runserver
All requests served correctly, but if start multiple workers like:
python manage.py run_gunicorn -w 10
Django respond with error to (about) half of my requests:
2013-06-13 18:02:39 [10205] [ERROR] Error handling request
Traceback (most recent call last):
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle_request
for item in respiter:
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/raven/middleware.py", line 27, in __call__
iterable = self.application(environ, start_response)
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 255, in __call__
response = self.get_response(request)
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 177, in get_response
signals.got_request_exception.send(sender=self.__class__, request=request)
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 170, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/__init__.py", line 68, in _rollback_on_exception
transaction.rollback_unless_managed(using=conn)
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/transaction.py", line 143, in rollback_unless_managed
connection.rollback_unless_managed()
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 232, in rollback_unless_managed
self._rollback()
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 59, in _rollback
return self.connection.rollback()
OperationalError: no connection to the server
I tried sqlite3 as DB backend for Django and it works fine. Do someone have the same problems with psycopg2?
Django==1.5
gunicorn==0.17.2
psycopg2==2.5

Sorry for disturbing. Problem was not in psycopg/Django/gunicorn. I use Nose for testing purposes:
==== settings.py ====
INSTALLED_APPS = INSTALLED_APPS + ('django_nose',)
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = ['--with-doctest']
when removed this lines, random errors disappear.

Related

SynchronousOnlyOperation error when upgrading from python 3.6 to python 3.7 using django channels

I've been attempting to upgrade python from 3.6 to 3.7 for our Django & Django channels application. With that change, Django throws a SynchronousOnlyOperation anytime any HTTP request is made (even if it has nothing to do with WebSockets). My guess is that somehow the python upgrade has made the Django check more strict.
I believe that Django channels are serving both the HTTP requests and WebSocket requests so it expects all code to be async compliant.
How do I get Django channels runserver to run the wsgi app synchronously, while the channel consumers asynchronously?
# project/asgi.py
application = ProtocolTypeRouter({"http": get_asgi_application(), "websocket": routing})
# project/wsgi.py
application = get_wsgi_application()
Stacktrace:
It's clear to me that the auth middleware that is running for a normal wsgi view is not async compliant, how can I get it to run in a sync environment?
ERROR Internal Server Error: /a/api
Traceback (most recent call last):
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 233, in _get_session
return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/___/___/___/___/apps/core/middleware.py", line 60, in __call__
request.is_user_verified = request.user.is_verified()
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/utils/functional.py", line 240, in inner
self._setup()
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/utils/functional.py", line 376, in _setup
self._wrapped = self._setupfunc()
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django_otp/middleware.py", line 38, in _verify_user
user.otp_device = None
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/utils/functional.py", line 270, in __setattr__
self._setup()
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/utils/functional.py", line 376, in _setup
self._wrapped = self._setupfunc()
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/contrib/auth/middleware.py", line 24, in <lambda>
request.user = SimpleLazyObject(lambda: get_user(request))
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/contrib/auth/middleware.py", line 12, in get_user
request._cached_user = auth.get_user(request)
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 174, in get_user
user_id = _get_user_session_key(request)
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 58, in _get_user_session_key
return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 65, in __getitem__
return self._session[key]
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 238, in _get_session
self._session_cache = self.load()
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 43, in load
s = self._get_session_from_db()
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 34, in _get_session_from_db
expire_date__gt=timezone.now()
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/db/models/query.py", line 425, in get
num = len(clone)
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/db/models/query.py", line 269, in __len__
self._fetch_all()
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/db/models/query.py", line 1303, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1154, in execute_sql
cursor = self.connection.cursor()
File "/___/___/.pyenv/versions/pd37/lib/python3.7/site-packages/django/utils/asyncio.py", line 24, in inner
raise SynchronousOnlyOperation(message)
django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
Versions
Django==3.1.1
channels==3.0.2
channels-redis==3.2.0
So a summary of what I've tried:
First, I have a channels app that had no database at all, no contrib apps except staticfiles.
I added database, DRF and one app with a single model and list/detail views
Enabled the sync http consumer:
# dwtools.routing
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
import romanize.routing
application = ProtocolTypeRouter(
{
"websocket": URLRouter(romanize.routing.websocket_urlpatterns),
"http": get_asgi_application(),
},
)
settings:
INSTALLED_APPS = [
"channels",
"romanize.apps.RomanizeConfig",
"django.contrib.staticfiles",
"rest_framework",
"agencies.apps.AgenciesConfig",
]
WSGI_APPLICATION = "dwtools.wsgi.application"
ASGI_APPLICATION = "dwtools.routing.application"
I can pull up DRF's standard views, create entries etc.
Then added a simple middleware that accesses the database (gets a count of the number of Agencies and puts it in request). Not even using MiddlewareMixin, just barebones init can call protocol.
System check identified no issues (0 silenced).
December 07, 2020 - 14:38:56
Django version 3.1.4, using settings 'dwtools.settings'
Starting ASGI/Channels version 3.0.2 development server at http://127.0.0.1:3401/
# ^^^^^^^^ ^^^^^^^^^^^ ( Channels runserver)
Quit the server with CONTROL-C.
HTTP GET /agencies/ 200 [0.05, 127.0.0.1:60460]
The stack uses local nginx to route to port 3401 for /ws (websocket) and /agencies (http). Perhaps you spot something...
Finally got to the bottom of this. For us, we were using gevent and had this line in our manage.py
# manage.py
import gevent
gevent.patch_all()
For whatever reason, that does not play nicely with python 3.7+, Django channels, and Django (where python 3.6, Django channels, and Django worked fine).
We were lucky and were able to remove this from our codebase; we did not figure out how to fix the gevent patch.

'server error please contact administrator' when i try to run python manage.py runserver

When I run python manage.py runserver, I receive a server error.
I have tried for several days now to resolve this problem on my own. I have followed several tutorials to no avail. I'am a beginner, so I am new to django and python. I'm hoping that it's just something that I'm overlooking. Can anyone please help me with this? Thank you so much in advance.
Here's what I'm receiving when I run python manage.py runserver.
(Django_Tutorial) Alexanders-MBP:Django_Tutorial alexanderbodiford$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
May 14, 2020 - 11:58:56
Django version 3.0.6, using settings None
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/Users/alexanderbodiford/Django_Tutorial/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 133, in __call__
response = self.get_response(request)
File "/Users/alexanderbodiford/Django_Tutorial/lib/python3.7/site-packages/django/core/handlers/base.py", line 74, in get_response
set_urlconf(settings.ROOT_URLCONF)
File "/Users/alexanderbodiford/Django_Tutorial/lib/python3.7/site-packages/django/conf/__init__.py", line 77, in __getattr__
val = getattr(self._wrapped, name)
File "/Users/alexanderbodiford/Django_Tutorial/lib/python3.7/site-packages/django/conf/__init__.py", line 205, in __getattr__
return getattr(self.default_settings, name)
AttributeError: module 'django.conf.global_settings' has no attribute 'ROOT_URLCONF'
[14/May/2020 11:59:02] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/Users/alexanderbodiford/Django_Tutorial/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 133, in __call__
response = self.get_response(request)
File "/Users/alexanderbodiford/Django_Tutorial/lib/python3.7/site-packages/django/core/handlers/base.py", line 74, in get_response
set_urlconf(settings.ROOT_URLCONF)
File "/Users/alexanderbodiford/Django_Tutorial/lib/python3.7/site-packages/django/conf/__init__.py", line 77, in __getattr__
val = getattr(self._wrapped, name)
File "/Users/alexanderbodiford/Django_Tutorial/lib/python3.7/site-packages/django/conf/__init__.py", line 205, in __getattr__
return getattr(self.default_settings, name)
AttributeError: module 'django.conf.global_settings' has no attribute 'ROOT_URLCONF'
[14/May/2020 11:59:02] "GET /favicon.ico HTTP/1.1" 500 59

Django static path is not properly set

I am trying to learn Django,
In settings.py I have set:
MEDIA_ROOT = '/home/hussain/django/ratingsite/ratingsite/media'
MEDIA_URL = 'media/'
STATIC_ROOT = '/home/hussain/django/ratingsite/ratingsite/static'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/home/hussain/django/ratingsite/ratingsite/static',)
I have my css files in my
/home/hussain/django/ratingsite/ratingsite/static/css/default.css
but when I try to access the webpage it doesnot load the css and gives Error.
"NetworkError: 500 Internal Server Error - http://localhost:8000/static/css/default.css"
I am new to this so I dont understand what is my root directory. what runs first and how Django tries to find the resources. If someone can guide me through this it would be great.
Guyz Guyz I was just doing hit and try and this happened. I renamed my static folder to staticfiles and then in STATICFILES_DIRS replaced the path from '/home/hussain/django/ratingsite/ratingsite/static/', to '/home/hussain/django/ratingsite/ratingsite/staticfiles/', and it worked. I have No Idea why. can someone please explain ?
output of python manage.py runserver --traceback
hussain#jarvis:~/django/ratingsite$ python manage.py runserver --traceback
Validating models...
0 errors found
December 08, 2013 - 01:48:39
Django version 1.5.4, using settings 'ratingsite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[08/Dec/2013 01:48:41] "GET / HTTP/1.1" 200 930
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 73, in __call__
return super(StaticFilesHandler, self).__call__(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 255, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in get_response
return self.serve(request)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 56, in serve
return serve(request, self.file_path(request.path), insecure=True)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/views.py", line 38, in serve
absolute_path = finders.find(normalized_path)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 238, in find
for finder in get_finders():
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 253, in get_finders
yield get_finder(finder_path)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 31, in wrapper
result = func(*args)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 275, in _get_finder
return Finder()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 62, in __init__
"The STATICFILES_DIRS setting should "
ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
[08/Dec/2013 01:48:42] "GET /static/css/default.css HTTP/1.1" 500 59
Traceback (most recent call last):
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 73, in __call__
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 73, in __call__
return super(StaticFilesHandler, self).__call__(environ, start_response)
return super(StaticFilesHandler, self).__call__(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 255, in __call__
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 255, in __call__
response = self.get_response(request)
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in get_response
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in get_response
return self.serve(request)
return self.serve(request)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 56, in serve
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 56, in serve
return serve(request, self.file_path(request.path), insecure=True)
return serve(request, self.file_path(request.path), insecure=True)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/views.py", line 38, in serve
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/views.py", line 38, in serve
absolute_path = finders.find(normalized_path)
absolute_path = finders.find(normalized_path)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 238, in find
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 238, in find
for finder in get_finders():
for finder in get_finders():
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 253, in get_finders
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 253, in get_finders
yield get_finder(finder_path)
yield get_finder(finder_path)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 31, in wrapper
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 31, in wrapper
result = func(*args)
result = func(*args)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 275, in _get_finder
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 275, in _get_finder
return Finder()
return Finder()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 62, in __init__
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 62, in __init__
"The STATICFILES_DIRS setting should "
"The STATICFILES_DIRS setting should "
ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
This makes sense now.
The problem is this as is written in your stacktrace:
ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
And per your initial configuration:
STATIC_ROOT = '/home/hussain/django/ratingsite/ratingsite/static'
STATICFILES_DIRS = (
'/home/hussain/django/ratingsite/ratingsite/static',)
You will not that both of these point to exactly the same directory. This is not allowed for the reason described below.
The ImproperlyConfigured error was fixed when you changed the location of one of these configurations (so they were no longer identical).
The solution here is to:
create a different STATIC_ROOT directory (we'd call this something like /public/static/) do not put any files in this directory this is where all of the static files are automatically collected to when your site is ready to publish.
put the location/s of the files that you are developing in the STATICFILES_DIRS.
When you are ready to publish your project you are able to run $ ./manage.py collectstatic which will go through all the apps and staticfiles directories your project uses and compile a set of all the "final" static files you need in the STATIC_ROOT directory ready for publication with your finished site.
If your STATIC_ROOT directory was included in the directories that was gone through by collectstatic there would obviously be a recursive loop.
Have you added the following to your urls.py?
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = patterns('',
# ... the rest of your URLconf goes here ...
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Per the instructions here:
https://docs.djangoproject.com/en/dev/howto/static-files/
Although you are getting a 500 error which suggests another problem.
What is the output of?:
$ python manage.py validate --traceback
Does this state some other kind of error?
How about the output of:
$ python manage.py shell
>>> from django.conf import settings
>>> print(settings.STATICFILES_DIRS)
As it is returning 500 rather than the expected 404 you could run:
$ python manage.py runserver --traceback
... and then see what the traceback history returns when you load the webpage.

Flask-frozen don’t work whereas flask is ok

I have a website using Flask. The main program is pretty long, so I’ve used a paste to show you the code. When I run it with ./site serve --debug it works perfectly, but I can’t freeze it with Flask-frozen. I have this error :
$ ./site build
Building website...
./site:240: MimetypeMismatchWarning: Filename extension of u'sitemap.xml' (type application/xml) does not match Content-Type: text/html; charset=utf-8
freezer.freeze()
Traceback (most recent call last):
File "./site", line 346, in <module>
parser.dispatch()
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/helpers.py", line 53, in dispatch
return dispatch(self, *args, **kwargs)
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/dispatching.py", line 123, in dispatch
for line in lines:
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/dispatching.py", line 199, in _execute_command
for line in result:
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/dispatching.py", line 182, in _call
result = args.function(*positional, **keywords)
File "./site", line 240, in build
freezer.freeze()
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/flask_frozen/__init__.py", line 140, in freeze
new_filename = self._build_one(url)
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/flask_frozen/__init__.py", line 250, in _build_one
% (response.status, url))
ValueError: Unexpected status '500 INTERNAL SERVER ERROR' on URL /403.html
If I delete the part about 403.html in site.py, I have the same error with 404, then 500, then contact.html, then /. And I can’t find why. Is there anybody who has an idea ?
Enable testing while freezing your application. It should produce more information about error.
#command
def build():
""" Builds this site.
"""
print("Building website...")
app.debug = False
app.testing = True
asset_manager.config['ASSETS_DEBUG'] = False
freezer.freeze()
local("cp ./static/*.ico ./build/")
local("cp ./static/*.txt ./build/")
local("cp ./static/*.xml ./build/")
print("Done.")
Frozen-flask uses app.test_client() look at it's docs.

Access denied to ClearDB database using Python/Django on Heroku

I'm trying to build a webapp on Heroku using Python/Django, and I just followed the tutorial to set up a Django project and push it to Heroku. However, I can never even get to the normal Django "It worked!" screen. Of course, that is because when I check heroku ps, there are never any processes running. There is no Procfile but according to the tutorial, that shouldn't matter for a Django app.
When I run heroku run python manage.py runserver, the following error occurs:
Unhandled exception in thread started by <bound method Command.inner_run of <dja
ngo.contrib.staticfiles.management.commands.runserver.Command object at 0x1ff819
0>>
Traceback (most recent call last):
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/com
mands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/bas
e.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/val
idation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/v
alidation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/b
ase.py", line 411, in get_server_version
self.cursor()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/__init_
_.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/b
ase.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/MySQLdb/__init__.py", line
81, in Connect
return Connection(*args, **kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/MySQLdb/connections.py", l
ine 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1044, "Access denied for user '<user>
'#'%' to database 'heroku_<####################>?reconnect=true'")
I did already set my DATABASE_URL to the value of CLEARDB_DATABASE_URL. Also, in the Django settings.py, I added as instructed:
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
Any help would be greatly appreciated.
That particular error was fixed after calling ClearDB. Turns out that the ?reconnect=true is only for Rails apps, and should be removed from the DATABASE_URL for Django apps.

Categories

Resources