为什么 Python imaplib return Errno 111: Connection refused 当我尝试在 GitPod 中实例化 IMAP4() 对象时?

Why does Python imaplib return Errno 111: Connection refused when I try to instantiate the IMAP4() object in GitPod?

我正在尝试在 GitPod 中使用 Python imaplib 库。

根据文档,我导入了 imaplib 并使用以下代码行实例化了 IMAP4 对象:

M = imaplib.IMAP4()

此 returns 以下消息:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gitpod/.pyenv/versions/3.8.12/lib/python3.8/imaplib.py", line 198, in __init__
    self.open(host, port)
  File "/home/gitpod/.pyenv/versions/3.8.12/lib/python3.8/imaplib.py", line 303, in open
    self.sock = self._create_socket()
  File "/home/gitpod/.pyenv/versions/3.8.12/lib/python3.8/imaplib.py", line 293, in _create_socket
    return socket.create_connection((host, self.port))
  File "/home/gitpod/.pyenv/versions/3.8.12/lib/python3.8/socket.py", line 808, in create_connection
    raise err
  File "/home/gitpod/.pyenv/versions/3.8.12/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

问题是 imaplib 无法连接到它自己的套接字,所以我应该先以某种方式在 GitPod 中激活该套接字吗?

来自the documentation

class imaplib.IMAP4(host='', port=IMAP4_PORT, timeout=None)
This class implements the actual IMAP4 protocol. The connection is created and protocol version (IMAP4 or IMAP4rev1) is determined when the instance is initialized. If host is not specified, '' (the local host) is used.

因此,它会尝试连接到本地计算机上的 IMAP 服务器。看起来有 none 或者至少不在端口 143.