错误使用Python imaplib处理
-
25-09-2019 - |
题
当我使用此行:
m = imaplib.IMAP4("some host")
我得到这个错误:
m = imaplib.IMAP4("some host")
File "C:\Python25\lib\imaplib.py", line 163, in __init__
self.open(host, port)
File "C:\Python25\lib\imaplib.py", line 230, in open
self.sock.connect((host, port))
File "<string>", line 1, in connect
error: (10061, 'Connection refused')
我会怎么做错误处理此错误?
解决方案
使用标准try/except
块:
import socket
try:
m = imaplib.IMAP4("some host")
except socket.error, e:
print "Error opening IMAP connection: ", e
不隶属于 StackOverflow