I need some help interpreting this error

Chris Green cl at isbd.net
Wed Feb 17 12:31:31 EST 2021


2QdxY4RzWzUUiLuE at potatochowder.com wrote:
> On 2021-02-17 at 16:42:03 +0000,
> Chris Green <cl at isbd.net> wrote:
> 
> > 2QdxY4RzWzUUiLuE at potatochowder.com wrote:
> > > On 2021-02-17 at 15:40:27 +0000,
> > > Chris Green <cl at isbd.net> wrote:
> > > 
> > > > I'm running this using Python 3.7 on a Linux system.
> > > > 
> > > > Most of the time (i.e. for a couple of days now) the program has been
> > > > satifactorily delivering mail messages, hundreds of them.  However one
> > > > mail message has provoked the following error:-
> > > > 
> > > >     chris at cheddar$ tail mail.err
> > > >     Traceback (most recent call last):
> > > >       File "/home/chris/.mutt/bin/filter.py", line 95, in <module>
> > > >         if sbstrip in msghdr["subject"]:
> > > >     TypeError: argument of type 'Header' is not iterable
> > > > 
> > > > 
> > > > But msghdr["subject"] is surely just a string isn't it?  Why is it 
> > > > complaining about something of type 'Header'?
> > > 
> > > Isn't it?  ;-)
> > > 
> > > First step:  Print msghdr["subject"] and its type to know for sure.  The
> > > worst case is that you'll verify your assumption.
> > > 
> > The documentation says "Headers are represented by customized
> > subclasses of str", so it's a sub-class of str.  
> 
> So we still don't know what the content of msghdr["subject"] is at the
> time the error occurs.  I don't mean to sound harsh, but that the
> documentation and the code are correct, and that they match, remain
> assumptions.  Sometimes, seeing an actual value tells you what went
> wrong (e.g., "oh, that's the sender's address, not the receiver's
> address," "oh, that's my 'time' class, not the one from the standard
> library").
> 
> The traceback tells you that msghdr["subject"] is of type Header.  Is
> Header a sub-class of str?
> 
That's exactly what puzzled me! The line that gets the value is:-

    msghdr["subject"] = msg.get("Subject", "unknown")

What I need to know is how that can return a value of type Header, and
not a str.

> Again, the worst case of looking at the value (whether in a log or in a
> debugger) is that you verify your assumption.
> 
> > > IIRC, the subject header is actually optional.  Maybe someone sent a
> > > message without a subject?  Is msghdr["subject"] None?
> > 
> > If you look at the code (and the documentation) if there's no subject
> > header I'll get the string "unknown", I've also tried sending myself
> > an E-Mail with no header and not provoked the error.
> 
> That's good news about subject-less emails not generating an error, and
> separate (possibly related) good news about your code handling an email
> without a subject header.  ;-)

I think the only sane approach at the moment may be to add a try:
except: and output some diagnostic information.  Though there may
still be an issue when trying to output the "what is it" object to the
error log of course.

-- 
Chris Green
·


More information about the Python-list mailing list