Python bindings: "can't subtract offset-naive and offset-aware datetimes" error when getting date/time timestamp

Post Reply
richardfearn
Newcomer
Posts: 6
Joined: Thu May 07, 2020 10:23 pm
Great Britain

Python bindings: "can't subtract offset-naive and offset-aware datetimes" error when getting date/time timestamp

Post by richardfearn » Thu May 07, 2020 10:38 pm

I can't log in to Trac at the moment, so thought I would ask here.

I'm using the Python 3 bindings for MythTV 31 on Ubuntu 20.04. It doesn't seem to be possible to get the timestamp from a MythTV datetime:

Code: Select all

>>> from MythTV.utility import dt
>>> t = dt.datetime.now()
>>> t.timestamp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/MythTV/utility/dt dot py", line 481, in timestamp
    return ((utc_naive - utc_epoch).total_seconds())
TypeError: can't subtract offset-naive and offset-aware datetimes
The same happens with MythTV 31 on Fedora 32:

Code: Select all

>>> from MythTV.utility import dt
>>> t = dt.datetime.now()
>>> t.timestamp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/MythTV/utility/dt dot py", line 481, in timestamp
    return ((utc_naive - utc_epoch).total_seconds())
TypeError: can't subtract offset-naive and offset-aware datetimes
(I had to change "dt dot py" in both the errors above to get past the forum rules on posting links)

User avatar
dnalorernst
Developer
Posts: 16
Joined: Mon Feb 17, 2020 8:03 pm
Austria

Re: Python bindings: "can't subtract offset-naive and offset-aware datetimes" error when getting date/time timestamp

Post by dnalorernst » Fri May 22, 2020 3:38 pm

Sorry for the late answer.
It is quite unusual to report bugs in the "General Development" section.

I can reproduce this error on Python3.8, but not with Python3.6.

Ticket #13622 opened.

richardfearn
Newcomer
Posts: 6
Joined: Thu May 07, 2020 10:23 pm
Great Britain

Re: Python bindings: "can't subtract offset-naive and offset-aware datetimes" error when getting date/time timestamp

Post by richardfearn » Fri May 22, 2020 4:50 pm

Thanks for creating the ticket! In the original post I said "I can't log in to Trac at the moment, so thought I would ask here". (There was an SSO bug meaning that new users like myself couldn't create a Trac account.)

This section ("General Development") seemed like the best place at the time.

Post Reply