python - 类型错误 : 'LazyImporter' object is not callable

标签 python email parsing

我有以下代码:

#!/usr/bin/python

import email
from email import Parser;
import sys
import subprocess
import json

input = sys.stdin.read();

mail = Parser().parsestr(input); #Line 11

这导致了以下错误消息:

Traceback (most recent call last):
  File "./mail.py", line 11, in <module>
    mail = Parser().parsestr(input);
TypeError: 'LazyImporter' object is not callable

有人对如何解决这个问题有任何建议吗?

最佳答案

您已经导入了模块parser,它当然不是函数或类(可调用)。但是,在模块内您将找到类 Parser(),因此您需要将代码更改为

mail = Parser.Parser().parsestr(input)

from email.parser import Parser     # this is the class
mail = Parser().parsestr(input)

关于python - 类型错误 : 'LazyImporter' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34348069/

相关文章:

python - 有人可以解释这条扭曲的事吗?

c# - 将收件人电子邮件地址添加到电子邮件正文

php - 为什么我不能在我的托管域中使用 swiftmailer 发送邮件,但从我的本地主机服务器发送邮件时却没有错误

c# - 为什么我用google 'smtp'发不了邮件?

java - 使用 SimpleDateFormat 解析时区格式的正确模式是什么

python - 如何避免继承成员使用自动摘要和自定义模板?

python - 无法将 numpy 数组转换为 SageMath 中的图形

python - sympy 中有多个用于 lambdify 的模块

parsing - 如何从 WebM 文件中提取音频

json - 如何在 Node-RED 函数中解析 JSON