Error: MySQL backend does not support timezone-aware datetimes when USE_TZ is False

437 views Asked by At

I have a problem with pagseguro's api, I'm using django 1.8 when I try to send a payment it shows the error "MySQL backend does not support timezone-aware datetimes when USE_TZ is False."

I can't change the USE_TZ setting to True, because it will interfere with other parts of the application. I've already changed where I was using timezone.now() to datetime.now() and even so this error still persists, does anyone have any solution for this?

Here's how the code of the api function is:

def checkout(self):
    self.build_params()
    headers = {
        'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
    }
    response = requests.post(
        self.checkout_url, self.params, headers=headers
    )

    data = {}

    if response.status_code == 200:
        root = xmltodict.parse(response.text)
        data = {
            'code': root['checkout']['code'],
            'status_code': response.status_code,
            'date': parse(root['checkout']['date']),
            'redirect_url': '{0}?code={1}'.format(
                self.redirect_url, root['checkout']['code']
            ),
            'success': True
        }
        checkout_realizado_com_sucesso.send(
            sender=self, data=data
        )
    else:
        data = {
            'status_code': response.status_code,
            'message': response.text,
            'success': False,
            'date': datetime.datetime.now()
        }
        checkout_realizado_com_erro.send(
            sender=self, data=data
        )

    checkout_realizado.send(
        sender=self, data=data
    )

    return data
0

There are 0 answers