'IMAPLIB "initial value must be str or none, not bytes" error

so im working on a script that basically runs in the background and pulls the data from any email that gets received containing a specific word in the subject and from a specific person. However, i cannot get it to parse the subject when running it since it keeps giving me an error that says "initial value must be str or none, not bytes" and i am unsure what this means or how to go about fixing it. Here is what i have so far:

import email
import imaplib
from bs4 import BeautifulSoup
import time
import sys

username = '[email protected]'
password = 'asdfasdfasasdf'

mail = imaplib.IMAP4_SSL('imap-mail.outlook.com')
(retcode, capabilities) = mail.login(username, password)
mail.list()

n=0
while True:
    mail.select('inbox')
    (retcode, messages) = mail.search(None, 'UNSEEN', '(SUBJECT "XXXXX- 
 ")', '(FROM "[email protected]")')
    if retcode == 'OK':
        for num in messages[0].split():
            n=n+1
            print('Processing Email ' + str(n) + ': ')
            typ, data = mail.fetch(num, '(RFC822)')
            for response_part in data:
                if isinstance(response_part, tuple):
                    original = email.message_from_string(response_part[1])
                    print("Subject: " + original['Subject'])
                    typ, data = mail.store(num,'+FLAGS','\\Seen')
                    time.sleep(120)


Solution 1:[1]

 email.message_from_string(data[0][1].decode('utf-8'))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Susaj S N