tags:

views:

49

answers:

0

I have just started to integrate django_digest into my app. As a start I have added the @httpdigest decorator to one of my views. If I try to connect to it I get a KeyError exception thrown in django_digest/backend/db.py . Depending on which db I configure I get a different KeyError in a different location. I am using Django 1.2.1, with MySql (also tested with sqlite). I am using the default values for all the settings options.

As far as I can see I have followed all instructions but am struggling all day with this. I am using the repository versions of django-digest and python-digest. Any steer would be greatly appreciated.

Tracebacks for sqlite and mysql below:

with sqlite:

Traceback (most recent call last):
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 674, in __call__
    return self.application(environ, start_response)
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 248, in __call__
    signals.request_finished.send(sender=self.__class__)
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/dispatch/dispatcher.py", line 162, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django_digest-1.8-py2.5.egg/django_digest/backend/db.py", line 16, in close_connection
    _connection.close()
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 186, in close
    if self.settings_dict['NAME'] != ":memory:":
KeyError: 'NAME'

with mysql:

Traceback (most recent call last):
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 674, in __call__
    return self.application(environ, start_response)
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/core/handlers/base.py", line 142, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/core/handlers/base.py", line 166, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/core/handlers/base.py", line 80, in get_response
    response = middleware_method(request)
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django_digest-1.8-py2.5.egg/django_digest/middleware.py", line 13, in process_request
    if (not self._authenticator.authenticate(request) and
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django_digest-1.8-py2.5.egg/django_digest/__init__.py", line 86, in authenticate
    partial_digest = self._account_storage.get_partial_digest(digest_response.username)
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django_digest-1.8-py2.5.egg/django_digest/backend/db.py", line 97, in get_partial_digest
    cursor = get_connection().cursor()
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/db/backends/__init__.py", line 75, in cursor
    cursor = self._cursor()
  File "/home/robm/projects/gcs/server/gcs2.5/lib/python2.5/site-packages/django/db/backends/mysql/base.py", line 281, in _cursor
    if settings_dict['USER']:
KeyError: 'USER'

Update - it seems that this is specific to Django 1.2 and the multidatabase backend. Modifying the database wrapper in django_digest's backend/db.py from:

_connection = backend.DatabaseWrapper({                                          
        'DATABASE_HOST': settings.DATABASE_HOST,                                 
        'DATABASE_NAME': settings.DATABASE_NAME,                                 
        'DATABASE_OPTIONS': settings.DATABASE_OPTIONS,                           
        'DATABASE_PASSWORD': settings.DATABASE_PASSWORD,                         
        'DATABASE_PORT': settings.DATABASE_PORT,                                 
        'DATABASE_USER': settings.DATABASE_USER,                                 
        'TIME_ZONE': settings.TIME_ZONE,                                         
        })                                                                       

to something like:

_connection = backend.DatabaseWrapper({
                'HOST': settings.DATABASE_HOST,
                'NAME': settings.DATABASE_NAME,
                'OPTIONS': settings.DATABASE_OPTIONS,
                'PASSWORD': settings.DATABASE_PASSWORD,
                'PORT': settings.DATABASE_PORT,
                'USER': settings.DATABASE_USER,
                'TIME_ZONE': settings.TIME_ZONE,
                })

should fix it.

For now I have switched to using HTTPBasicAuth with https instead, but hopefully next week I'll get a chance to do a patch.