开发者

error handling with imaplib in python

开发者 https://www.devze.com 2023-02-03 04:44 出处:网络
When I use this line: m = imaplib.IMAP4(\"some host\") I get this error: m = imaplib.IMAP4(\"some host\")

When I use this line:

m = imaplib.IMAP4("some host")

I get this error:

 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开发者_Go百科 refused')

How would I do error handling for this error?


Use a standard try/except block:

import socket

try:
    m = imaplib.IMAP4("some host")
except socket.error, e:
    print "Error opening IMAP connection: ", e
0

精彩评论

暂无评论...
验证码 换一张
取 消