Django: 'unicode' object has no attribute 'tzinfo'. Production server only

谁说我不能喝 提交于 2019-12-14 03:49:01

问题


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.

来源:https://stackoverflow.com/questions/35758154/django-unicode-object-has-no-attribute-tzinfo-production-server-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!