Domanda

Quando uso questa linea:

m = imaplib.IMAP4("some host")

ottengo questo errore:

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

Come farei la gestione degli errori per questo errore?

È stato utile?

Soluzione

Usa un blocco try/except di serie:

import socket

try:
    m = imaplib.IMAP4("some host")
except socket.error, e:
    print "Error opening IMAP connection: ", e
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top