On Mon, Feb 15, 2010 at 2:31 PM, Stephen Hansen <apt.shan...@gmail.com> wrote: > On Mon, Feb 15, 2010 at 10:53 AM, BJ Swope <bigbluesw...@gmail.com> wrote: >> >> File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz >> if data[9] is None: >> TypeError: 'NoneType' object is unsubscriptable >> >> I'm parsing a bunch of spam and using the date field from the spams >> for a date-time stamp. >> >> I've fixed the lib on my box to place the call inside a try/except >> clause to catch the exception now, but it seems the module has a bug >> in it. > > While there may or may not be a bug in the library, I don't think its where > you're fixing. Just because an exception occurs in a function doesn't mean > that function is broken: its documented as accepting a 10 item tuple, only. > Functions in the stdlib generally -should- throw exceptions on invalid > input. > Someone's passing None into it, which its not allowed to do. So -that's- > where the bug probably is, I think. (Although it may not be the immediate of > mktime_tz; it could be happening higher up on the stack) > Advice: Always post complete tracebacks to c.p.l/python-list :) > --S
>From the module: def mktime_tz(data): """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" if data[9] is None: # No zone info, so localtime is better assumption than GMT return time.mktime(data[:8] + (-1,)) else: t = time.mktime(data[:8] + (0,)) return t - data[9] - time.timezone It appears that the module is trying to accommodate the potential missing TZ data because poorly written emails are missing the TZ data. I discarded all the crontab emails that had the full traceback in them. I took out the try/except clause in the hopes that I'll get another exception soon. If I do I'll post the entire exception traceback. -- http://mail.python.org/mailman/listinfo/python-list