Datetime.strptime - NonType error on second use - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: Datetime.strptime - NonType error on second use (/showthread.php?tid=112916) Pages:
1
2
|
Datetime.strptime - NoneType error on second use - Eldorado - 2011-10-21 I'm having an odd issue when converting date formats using datetime, I'm running on Windows the Oct. 17th build, but happens on any other pre-Eden nightly I've tested on In Dharma I believe it is running Python 2.4 so is not affected as the strptime attribute is in the 'time' library, did not get moved to datetime until 2.5 Basically I have the following quick function to convert a date to a different format, and I'm executing it in a small tester video addon: Code: from datetime import datetime I have the legacy check in for Dharma users, I can assure you that piece of code is not causing any issues Doing a quick call to this method to return just the year from a given date works fine: Code: year = convert_date('2011-01-01', '%Y-%m-%d', '%Y') But if I run the addon a 2nd time (the only thing it does is executes this code) I get the following error: Code: attribute of type 'NoneType' is not callable I need to shut down xbmc and restart it for it to work again, then on the 2nd run it fails with this error.. I can reproduce this time and time again. I can call this method a hundred times over on the first run and will work fine. It's always on the 2nd time launching the addon If I revert back to Dharma 10.1 it will use time.strptime and works perfect Any ideas? This code works perfectly fine in Python Idle 2.7 no matter how many times I run it.. - takoi - 2011-10-23 I'm having similar issues with the strptime function, except i cant even run it a first time. Im using linux with system python version 2.7.1. Its very odd because it works fine in the interpreter, but when trying to run it from xbmc its fails with the same message: "attribute of type 'NoneType' is not callable". - Eldorado - 2011-10-24 I'm glad I'm not the only one! Can anyone else test this on pre-Eden? Here's a more simpler piece to test with: Code: from datetime import datetime First run: Code: NOTICE: 2011-01-01 00:00:00 Second run: Code: ERROR: Traceback (most recent call last): Same issue - shanemeagher - 2011-12-20 @ Eldorado, Have you come across any more on this issue? Having the same issue: works on first try after starting but fails on repeated attempts. Works fine when I try in IDLE. Running Python 2.7.2 and Pre-Eden (PVR-Margo compiled on 2011-12-04) on Win7 64bit - Eldorado - 2011-12-20 Yep I was able to fix it by using the new python, only works with pre-Eden In your addon.xml, set python to 2.0 <import addon="xbmc.python" version="2.0" /> - k_zeon - 2011-12-22 Eldorado Wrote:I'm glad I'm not the only one! Hey Eldorado I found this below and it got me to thinking. Quote:classmethod datetime.strptime(date_string, format) On first run you get a=2011-01-01 00:00:00 but time is nothing In VB i define what a variable will be ie Dim a as Date or String What if you put a='' to force it into a string at the begining of your routine or format it as a DateTime variable It could be that 00:00:00 is causing an issue. OR i could just be wrong. ..... nevermind also seen this. maybe a clue ie the %H:%M:%S from datetime import datetime dt = '16-MAR-2010 03:37:04' datetime.strptime(dt, " %d-%b-%Y %H:%M:%S ") datetime.datetime(2010, 3, 16, 3, 37, 4) RE: - Leopold - 2012-10-12 (2011-12-20, 18:25)Eldorado Wrote: Yep I was able to fix it by using the new python, only works with pre-Eden I've got exactly the same problem in Eden and the latest nightlies. I tried this solution but it didn't help. Have you come across this again since? RE: Datetime.strptime - NonType error on second use - ronie - 2012-10-12 as far as i understand it's a known issue with python. if you google for a bit, you'll find several reports like this one: https://mail.python.org/pipermail/python-list/2009-June/540636.html the workaround seems to be: Code: import datetime edit: http://bugs.python.org/issue27400 RE: Datetime.strptime - NonType error on second use - divingmule - 2012-10-12 Here is how I worked around the issue in one add-on using time module - Code: try: RE: Datetime.strptime - NonType error on second use - Leopold - 2012-10-15 (2012-10-12, 17:17)ronie Wrote: as far as i understand it's a known issue with python. Thanks but this didn't work. I think it might fix a slightly different problem to mine. (2012-10-12, 18:28)divingmule Wrote: Here is how I worked around the issue in one add-on using time module - Thanks, this works, but I ended up taking a simpler example from the Python doc. Code: try: I was hoping there wouldn't be a need to work around the problem but at least it's working now. RE: Datetime.strptime - NonType error on second use - bossanova808 - 2013-01-19 Just thankyou - helped me solve a very confusing problem!! RE: Datetime.strptime - NonType error on second use - hewligun - 2014-03-31 Code: try: I have this code above but for some reason its not displaying the time correctly. That above shows 1 hour ahead of what the current time actually is. If I set it to US/Pacific it puts it in eastern time... Any ideas how I can get this to the current PST time? or at least fix the daylight savings issue I assume it is? RE: Datetime.strptime - NonType error on second use - jgauthier - 2016-01-07 Wow.. I'm totally going to necro this thread! I running into this exact problem, years later on a Helix platform with Kodi 2.7. The first run is acceptable, subsequent runs throw TypeError: attribute of type 'NoneType' is not callable Strange, indeed. RE: Datetime.strptime - NonType error on second use - tmelin - 2016-07-02 I also bumped into this on a Jarvis platform just now. Workaround that also worked for me: Code: Code: RE: Datetime.strptime - NonType error on second use - zbyna - 2016-09-16 (2016-07-02, 21:29)tmelin Wrote: I also bumped into this on a Jarvis platform just now. Workaround that also worked for me: The same problem. Can confirm workaround. Big thanks !!! |