Unable to parse connection string: "" when using django cache

622 views
Skip to first unread message

nav

unread,
Mar 10, 2016, 7:44:21 PM3/10/16
to Django users
Hi,

I am configuring the memcache backend to use with django and have the following things setup:

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}

CACHE_MIDDLEWARE_ALIAS = 'django.core.cache.backends.memcached.MemcachedCache'
CACHE_MIDDLEWARE_SECONDS = 3 * 60 * 60 # 3 hours in seconds
CACHE_MIDDLEWARE_KEY_PREFIX = ''

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
# the order of our middleware matters!
# should be later than AuthenticationMiddleware,
# but earlier than HorizonMiddleware
'horizon.middleware.HorizonMiddleware',
)

I keep hitting the error message "Unable to parse connection string: "" which is coming from the memcache.py from the python-memcached binding. This is because the tuple of cache servers is empty instead of containing 127.0.0.1:11211.

I have verified that the memcache daemon is up and running and have added and retrieved data from it.

Hence, I believe that there is something wrong with my configuration and I have been trying to figure out what is wrong for hours. I hope someone can lend some assistance.

Many thanks,
nav
P.S. This is the first time I am setting up a cache so I may need some explanation of some concepts.

 

Nandakumar Chandrasekhar

unread,
Mar 10, 2016, 8:02:37 PM3/10/16
to django...@googlegroups.com
Sorry forgot to add the traceback I am getting:

Internal Server Error: /
Traceback (most recent call last):
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 88, in get_response
    response = middleware_method(request)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/middleware/cache.py", line 147, in process_request
    cache_key = get_cache_key(request, self.key_prefix, 'GET', cache=self.cache)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/utils/cache.py", line 212, in get_cache_key
    headerlist = cache.get(cache_key, None)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 75, in get
    val = self._cache.get(key)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 163, in _cache
    self._client = self._lib.Client(self._servers, pickleProtocol=pickle.HIGHEST_PROTOCOL)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 223, in __init__
    self.set_servers(servers)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 302, in set_servers
    for s in servers]
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 1317, in __init__
    raise ValueError('Unable to parse connection string: "%s"' % host)
ValueError: Unable to parse connection string: ""
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52825)
----------------------------------------
[11/Mar/2016 00:59:39] "GET / HTTP/1.1" 500 118134
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 86, in run
    self.finish_response()
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 131, in finish_response
    self.close()
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/simple_server.py", line 36, in close
    SimpleHandler.close(self)
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 259, in close
    self.result.close()
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/http/response.py", line 305, in close
    signals.request_finished.send(sender=self._handler_class)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 185, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 100, in close
    self._cache.disconnect_all()
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 163, in _cache
    self._client = self._lib.Client(self._servers, pickleProtocol=pickle.HIGHEST_PROTOCOL)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 223, in __init__
    self.set_servers(servers)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 302, in set_servers
    for s in servers]
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 1317, in __init__
    raise ValueError('Unable to parse connection string: "%s"' % host)
ValueError: Unable to parse connection string: ""
[11/Mar/2016 00:59:39] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 599, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 126, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 655, in __init__
    self.handle()
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/simple_server.py", line 131, in handle
    handler.run(self.server.get_app())
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 92, in run
    self.close()
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/simple_server.py", line 33, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
Internal Server Error: /favicon.ico
Traceback (most recent call last):
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 88, in get_response
    response = middleware_method(request)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/middleware/cache.py", line 147, in process_request
    cache_key = get_cache_key(request, self.key_prefix, 'GET', cache=self.cache)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/utils/cache.py", line 212, in get_cache_key
    headerlist = cache.get(cache_key, None)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 75, in get
    val = self._cache.get(key)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 163, in _cache
    self._client = self._lib.Client(self._servers, pickleProtocol=pickle.HIGHEST_PROTOCOL)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 223, in __init__
    self.set_servers(servers)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 302, in set_servers
    for s in servers]
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 1317, in __init__
    raise ValueError('Unable to parse connection string: "%s"' % host)
ValueError: Unable to parse connection string: ""
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52828)
----------------------------------------
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 86, in run
    self.finish_response()
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 131, in finish_response
    self.close()
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/simple_server.py", line 36, in close
    SimpleHandler.close(self)
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 259, in close
    self.result.close()
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/http/response.py", line 305, in close
    signals.request_finished.send(sender=self._handler_class)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 185, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 100, in close
    self._cache.disconnect_all()
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 163, in _cache
    self._client = self._lib.Client(self._servers, pickleProtocol=pickle.HIGHEST_PROTOCOL)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 223, in __init__
    self.set_servers(servers)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 302, in set_servers
    for s in servers]
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/memcache.py", line 1317, in __init__
    raise ValueError('Unable to parse connection string: "%s"' % host)
ValueError: Unable to parse connection string: ""
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 599, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/Users/nchandrasekhar/PycharmProjects/horizon/.venv/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 126, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 655, in __init__
    self.handle()
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/simple_server.py", line 131, in handle
    handler.run(self.server.get_app())
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 92, in run
    self.close()
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/simple_server.py", line 33, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/zuPKMjHyWbs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2131332e-33cf-4d73-a9b7-2107bf07b2c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nav

unread,
Mar 11, 2016, 6:46:18 PM3/11/16
to Django users
Setting the key CACHE_MIDDLEWARE_ALIAS to 'default' fixes the issue

Cheers,
Nanda
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.

jorr...@gmail.com

unread,
Mar 17, 2016, 10:39:41 AM3/17/16
to Django users
As an aside, it looks like you're including CommonMiddleware twice.

Nandakumar Chandrasekhar

unread,
Mar 17, 2016, 1:00:06 PM3/17/16
to django...@googlegroups.com
Thanks I had not caught that but I am not sure if that is the issue.

On Thu, Mar 17, 2016 at 7:39 AM, <jorr...@gmail.com> wrote:
As an aside, it looks like you're including CommonMiddleware twice.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/zuPKMjHyWbs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages