繁体   English   中英

Python 错误:''ModuleNotFoundError:没有名为'email.Utils'的模块'

[英]Python error: ''ModuleNotFoundError: No module named 'email.Utils''

import fileinput
import email
from email.Utils import parseaddr

def parse():
    raw_message = ''.join([line for line in fileinput.input()])
    message = email.message_from_string(raw_message)
    text_plain = None
    text_html = None

for part in message.walk():
    if part.get_content_type() == 'text/plain' and text_plain is None:
        text_plain = part.get_payload()
    if part.get_content_type() == 'text/html' and text_html is None:
        text_html = part.get_payload()

return {
  'to': parseaddr(message.get('To'))[1],
  'from': parseaddr(message.get('From'))[1],
  'delivered to': parseaddr(message.get('Delivered-To'))[1],
  'subject': message.get('Subject'),
  'text_plain': text_plain,
  'text_html': text_html,
}

if __name__ == '__main__':
    print(parse())

this is my code I am trying to make an email parser and I imported email and I installed email module using pip and I use python 3.9 I tried eveything to fix it, is there any answer or altervatives? PS。 这不是全部代码

Utils不应大写。 这是更正后的行:

from email.utils import parseaddr

来源: https://docs.python.org/3/library/email.utils.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM