我尝试从邮件服务器获取输入消息。在 Windows 10 中,一切正常。当我将代码传输到 Linux服务器时-我看到错误'utf-8'编解码器无法解码字节0xc7
print("Connecting to {}...".format(server))
imap = imaplib.IMAP4_SSL(server)
print("Connected! Logging in as {}...".format(login));
imap.login(login, password)
print("Logged in! Listing messages...");
status, select_data = imap.select('INBOX')
nmessages = select_data[0].decode('utf-8')
status, search_data = imap.search(None, 'ALL')
for msg_id in search_data[0].split():
status, msg_data = imap.fetch(msg_id, '(RFC822)')
msg_raw = msg_data[0][1].decode("utf8") // error here
我添加了shebang-同样的问题。脚本字符集-utf8
# -*- coding: utf-8 -*-
#!/usr/bin/env python3