1
Я пытаюсь разобрать содержание сообщения электронной почты, содержащего html-содержимое.unicode() аргумент 2 должен быть строкой не None
import imaplib
import email
....
elif part.get_content_type() == "text/html":
# if html is None:
html = ""
html += unicode(part.get_payload(decode=True),part.get_content_charset(),'replace').encode('utf8','replace')
save_string = str("C:Dumpgmailemail2"+".eml")
# location on disk
myfile = open(save_string, 'a')
myfile.write(str(html))
#myfile.write(html.decode('utf-8'))
myfile.close()
Но это дает мне ошибку:
Traceback (most recent call last):
File "extract.py", line 22, in <module>
html += unicode(part.get_payload(decode=True),part.get_content_charset(),"replace").encode('utf8','replace')
TypeError: unicode() argument 2 must be string, not None
'часть .get_content_charset() 'возвращает None, используйте значение по умолчанию –