Question

Quand j'utilise cette ligne:

m = imaplib.IMAP4("some host")

Je reçois cette erreur:

 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')

Comment puis-je faire la gestion des erreurs pour cette erreur?

Était-ce utile?

La solution

Utilisez un bloc standard try/except:

import socket

try:
    m = imaplib.IMAP4("some host")
except socket.error, e:
    print "Error opening IMAP connection: ", e
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top