I am using emencia.django.newsletter. When I run `python manage.py send_newsletter’ I get this error
if self.newsletter.sending_date <= datetime.now() and \
TypeError: can't compare offset-naive and offset-aware datetimes
This is where the error comes from:
def can_send(self):
"""Check if the newsletter can be sent"""
if self.test:
return True
if self.newsletter.sending_date <= datetime.now() and\
(self.newsletter.status == Newsletter.WAITING or\
self.newsletter.status == Newsletter.SENDING):
return True
return False
I use Django 1.4
Any ideas?
Your
sending_datevalue is timezone aware, butdatetime.now()is timezone naive. As the error message says, you cannot compare them.The answer is to convert
nowinto a timezone aware datetime before doing the comparison.For more information see the Django docs on naive and aware datetime objects.