v20 Strange datetime error?
#1
I am writing a video addon and to parse the EPG I need to convert from the API provided date format to the EPG compatible version. Upon writing the code that handles this logic for me, I encountered a strange issue:

Code:
import sys
from datetime import datetime
sys.stderr.write(datetime.strptime("14/08/2023 21:45:00", "%d/%m/%Y %H:%M:%S").strftime("%Y%m%d%H%M%S %z"))

If I run this, I get:

Code:
2023-08-16 15:58:49.543 T:38735 error <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <class 'TypeError'>
Error Contents: 'NoneType' object is not callable
Traceback (most recent call last):
File "/home/steve/.kodi/addons/plugin.video.test/default.py", line 781, in <module>
update_epg(session)
File "/home/steve/.kodi/addons/plugin.video.test/default.py", line 715, in update_epg
sys.stderr.write(datetime.strptime("14/08/2023 21:45:00", "%d/%m/%Y %H:%M:%S").strftime("%Y%m%d%H%M%S %z"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not callable
-->End of Python script error report<--

Other dates work fine... And if I run the same thing from my regular bash shell's python 3.11.3 installation, I get the expected result:

Code:
>>> a = '14/08/2023 21:45:00'
>>> datetime.strptime(a, "%d/%m/%Y %H:%M:%S").strftime("%Y%m%d%H%M%S %z")
'20230814214500 '

Can you reproduce as well? Any possible workarounds?

I am running Kodi v20.2 on an Arch laptop.

Thanks
Reply
#2
looks like this python bug - https://bugs.python.org/issue27400


workaround code -


python:
s = "14/08/2023 21:45:00"
try:
    refdatim = datetime.strptime(s, '%d/%m/%Y %H:%M:%S')
except TypeError:
    import time
    refdatim = datetime.fromtimestamp(time.mktime(time.strptime(s, '%d/%m/%Y %H:%M:%S')))
    
print(refdatim.strftime("%Y%m%d%H%M%S %z"),file=sys.stderr)
Reply
#3
Thanks a lot. Meanwhile I figured that there is even a Kodi wiki about this issue: https://kodi.wiki/view/Python_Problems#d...e.strptime Your suggested workaround works well.
Reply

Logout Mark Read Team Forum Stats Members Help
Strange datetime error?0