问题
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