My python program is calling smtplib.sendmai l which ultimately calls socket.py to open port 25 on the specified host. My issue is that if an error is raised on that attempted socket connection, I can't seem to catch the exception and handle it gracefully - I get the traceback. 'except socket.error:' is being bypassed for some reason that I can't figure out. Thoughts on what I am doing wrong? Thanks!
Traceback (most recent call last):
File "scaladir.p y", line 57, in <module>
s = smtplib.SMTP('1 0.255.208.122')
File "C:\Program Files (x86)\Python26\ lib\smtplib.py" , line 239, in __init__
(code, msg) = self.connect(ho st, port)
File "C:\Program Files (x86)\Python26\ lib\smtplib.py" , line 295, in connect
self.sock = self._get_socke t(host, port, self.timeout)
File "C:\Program Files (x86)\Python26\ lib\smtplib.py" , line 273, in _get_socke
t
return socket.create_c onnection((port , host), timeout)
File "C:\Program Files (x86)\Python26\ lib\socket.py", line 561, in create_conn
ection
raise error, msg
socket.error: [Errno 10013] An attempt was made to access a socket in a way forb
idden by its access permissions
Code:
s = smtplib.SMTP('10.255.208.122') try: s.sendmail(sender, receiver, msg.as_string()) wrtevt('Success') s.quit() except socket.error: errno, errstr = sys.exc_info()[:2] if errno == socket.timeout: print "There was a timeout" else: print "There was some other socket error"
Traceback (most recent call last):
File "scaladir.p y", line 57, in <module>
s = smtplib.SMTP('1 0.255.208.122')
File "C:\Program Files (x86)\Python26\ lib\smtplib.py" , line 239, in __init__
(code, msg) = self.connect(ho st, port)
File "C:\Program Files (x86)\Python26\ lib\smtplib.py" , line 295, in connect
self.sock = self._get_socke t(host, port, self.timeout)
File "C:\Program Files (x86)\Python26\ lib\smtplib.py" , line 273, in _get_socke
t
return socket.create_c onnection((port , host), timeout)
File "C:\Program Files (x86)\Python26\ lib\socket.py", line 561, in create_conn
ection
raise error, msg
socket.error: [Errno 10013] An attempt was made to access a socket in a way forb
idden by its access permissions
Comment