Tag Archives: AttributeError: ‘unicode’ object has no attribute ‘tzinfo’

Python AttributeError: ‘unicode’ object has no attribute ‘tzinfo’

Internal Server Error: /demo/machineinfo.html
Traceback (most recent call last):
File “C:\Python27\lib\site-packages\django\core\handlers\exception.py”, line 41, in inner
response = get_response(request)
File “C:\Python27\lib\site-packages\django\core\handlers\base.py”, line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File “C:\Python27\lib\site-packages\django\core\handlers\base.py”, line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “G:\python\project\myApp\machineviews.py”, line 25, in htmlmachineinfo
print machineinfo.objects.filter(serialNumber=machineser)
File “C:\Python27\lib\site-packages\django\db\models\query.py”, line 226, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File “C:\Python27\lib\site-packages\django\db\models\query.py”, line 250, in __iter__
self._fetch_all()
File “C:\Python27\lib\site-packages\django\db\models\query.py”, line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File “C:\Python27\lib\site-packages\django\db\models\query.py”, line 62, in __iter__
for row in compiler.results_iter(results):
File “C:\Python27\lib\site-packages\django\db\models\sql\compiler.py”, line 842, in results_iter
row = self.apply_converters(row, converters)
File “C:\Python27\lib\site-packages\django\db\models\sql\compiler.py”, line 827, in apply_converters
value = converter(value, expression, self.connection, self.query.context)
File “C:\Python27\lib\site-packages\django\db\backends\mysql\operations.py”, line 239, in convert_datetimefield_value
value = timezone.make_aware(value, self.connection.timezone)
File “C:\Python27\lib\site-packages\django\utils\timezone.py”, line 285, in make_aware
return timezone.localize(value, is_dst=is_dst)
File “C:\Python27\lib\site-packages\pytz\__init__.py”, line 222, in localize
if dt.tzinfo is not None:
AttributeError: ‘unicode’ object has no attribute ‘tzinfo’

The temporary solution takes the database

models.DateTimeField(auto_now_add=True)
The relevant time statement is commented out first, and then executed.
I'll update it later when I have a solution.