3

I'm stumped. With my local set up (python manage.py runserver) everything runs fine. With my production set up (wsgiserver.CherryPyWSGIServer), I get 'unicode' object has no attribute 'tzinfo' when my program tries to convert datetime2(7) from the database to local time in the pytz module. Using Django 1.9.

  • Both set ups use django-pyodbc-azure to connect to the same mssql database. In fact to troubleshoot this, both use the same settings files.

    # settings.py
    ...
    
    DATABASES = {
        'default': {
            'ENGINE': 'sql_server.pyodbc',
            'NAME': 'dbname',
            'OPTIONS': {
                'use_mars': True,
                'use_legacy_datetime': True,
                'driver': 'SQL Server Native Client 11.0'
            }
        }
    }
    
    ...
    
    # Relevant to runserver command:
    WSGI_APPLICATION = 'wsgi.application'
    
  • Production is run by running this file:

    # deploy_server.py
    
    from . import wsgi
    sn = socket.gethostname()
    
    server = wsgiserver.CherryPyWSGIServer(
        ('0.0.0.0', 8009), wsgi.application, server_name=sn,
    )
    server.start()
    
  • Local is run with Djangos runserver command

  • wsgi.py:

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
    
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    

I initially had the same problem locally, but configuring the database with the options shown fixed that.

Any help would be awesome.

BottleZero
  • 893
  • 6
  • 13
  • 1
    Did you try this answer: http://stackoverflow.com/questions/16492031/how-to-fix-this-error-unicode-object-has-no-attribute-tzinfo?rq=1 ? – karthikr Mar 02 '16 at 21:17
  • @karthikr - Yes, that is how I fixed the problem when it occurred with my local settings. For some reason that solution doesn't work with my production set up. – BottleZero Mar 02 '16 at 21:41

0 Answers0