I need some help interpreting this error

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


Stestagg <stestagg at gmail.com> wrote:
> I don't particularly like to encourage this shotgun help request because,
> as previous commenter suggests, debugging this yourself is best.
> 
> Sometimes debugging is super hard, and especially so when uncommon
> situations occur, but it's always far easier to debug things when you have
> visibility into the system under test.
> 
> However, in this case, the email code is super complex, and this scenario
> also looks very uncommon, but not unique: (
> https://github.com/Sydius/mbox-to-txt/issues/2), so you successfully
> nerd-sniped me :).
> 
> My *guess*, from reading the python standard library source code is that
> you came across an email with some content in the subject line that is
> considered a "surrogate", roughly, some badly encoded unicode or binary
> data in it.
> 
> When this happens, the code in some situations (depending on the policy...)
> may return a header.Header() instance, rather than a
> headerregistry.UniqueUnstructuredHeader
> (which would have had a headerregistry.BaseHeader (mro: str) dynamically
> attached).
> 
> header.Header() does not inherit from str, and thus would throw the
> traceback you observed.
> 
Ah, thank you, a possible explanation.


> Your suggestion of a try: catch: may make sense, alternately, you could
> wrap the result in a call to str():
> 
> if sbstrip in str(msghdr["subject"]):
> 
> which should attempt to encode the binary into some form of string object
> for comparison (I haven't checked exactly what would happen, beyond: it
> tries).
> 
Yes, I did consider the str() approach but it feels a bit like making
the problem go away without actually fixing it.

However since the code in question is only 'cosmetic' (removing
unwanted [list name] from the subject, it's not all *that* important
to handle it properly.  I just need to stop the error from killing my
program.


> It should be possible to create a test mbox with some funky bytes in the
> subject, and try to reproduce it that way.
> 
That's a point, with the clues you have given me I can try some 'bad'
subject text and see if I can reproduce the error.

Thanks again.

-- 
Chris Green
·


More information about the Python-list mailing list