Python and pop3 to parse emails
<p>Looked through people's past attempts to do similar things. The code I have found as a basis is</p>

<pre><code>import poplib
from email import parser

pop_conn = poplib.POP3_SSL('pop.gmail.com')
pop_conn.user('---------')
pop_conn.pass_('--------')
#Get messages from server:
messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
# Concat message pieces:
messages = ['\n'.join(mssg[1]) for mssg in messages]
#Parse message intom an email object:
messages = [parser.Parser().parsestr(mssg) for mssg in messages]
for message in messages:
    print(message['subject'])
    print(message['body'])
pop_conn.quit()
</code></pre>

<p>I keep getting an error:</p>

<pre><code>Traceback (most recent call last):
    File "E:\False Apparition\Desktop\test.py", line 10, in &lt;module&gt;
        messages = ['\n'.join(''.join(mssg[1]) for mssg in messages)]
    File "E:\False Apparition\Desktop\test.py", line 10, in &lt;genexpr&gt;
        messages = ['\n'.join(''.join(mssg[1]) for mssg in messages)]
TypeError: sequence item 0: expected str instance, bytes found
</code></pre>

<p>Is this because I am using python 3.6 instead of an earlier version? Essentially I want to be able to quickly parse a server status email to deliver the important stats, but only emails that have a specific subject line (as I could get other emails). I'm familiar with parsing but without being able to get a subject or the body I'm a bit stuck.</p>

<p>Many thanks in advance.</p>