【问题标题】:I get a "module 'imaplib' has no attribute 'IMAP4_SSL'" when I run my program like windows service当我像 Windows 服务一样运行我的程序时,我得到一个“模块‘imaplib’没有属性‘IMAP4_SSL’”
【发布时间】:2021-01-05 19:57:47
【问题描述】:

我用 Python 制作了一个 Windows 服务来阅读一些邮件并获取一些信息。 当我在带有 Pycharm 的 win7 开发人员机器中使用它时,它运行良好,但是当我尝试在 windows 2012 服务器中运行它时(这就是它可以工作的地方),我收到“模块 'imaplib' 没有属性 'IMAP4_SSL' "

有趣的是,当我在服务器中的 python 控制台中输入相同的命令时,它并没有给我任何错误。

代码是:

    def open_imap():
        # Read the config file
        config2 = configparser.ConfigParser()
        config2.read(os.path.join('C:\\', 'IziPayMail.ini'))
        # Connect to the server
        hostname = config2.get('Mail', 'hostname')
        logging.info('Hostname = ' + hostname)
        connection = imaplib.IMAP4_SSL(hostname)
        logging.info('Conectado a ' + hostname)

        # Login to our account
        username = config2.get('Mail', 'username')
        password = config2.get('Mail', 'password')
        connection.login(username, password)
        logging.info('Logeado a ' + username)
        
        return connection

有人知道会发生什么吗?

克劳迪奥

【问题讨论】:

  • import ssl 有效吗?它可能无法找到 SSL 库,因此它忽略了对 IMAP4-SSL 的支持。
  • 是的,导入 ssl 工作正常
  • 我也在 windows 2012 中安装了 pycharm,脚本运行良好。似乎问题仅在于它作为服务运行时。我会继续测试

标签: python ssl windows-server-2012-r2 imaplib


【解决方案1】:

经过大量尝试,我发现我可以像运行 Windows Server 一样运行它。我也注意到它与 SSL 有关。 我累了,我将协议更改为没有 SSL 的 IMAP……现在它可以工作了。 我真的很想找到一个真正的答案,但现在使用 IMAP 是可行的。

【讨论】:

    猜你喜欢
    • 2019-09-15
    • 1970-01-01
    • 2022-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多