I need some help interpreting this error

2QdxY4RzWzUUiLuE at potatochowder.com 2QdxY4RzWzUUiLuE at potatochowder.com
Wed Feb 17 12:04:28 EST 2021


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?

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.  ;-)


More information about the Python-list mailing list