[New-bugs-announce] [issue17498] error responses from server are masked in smtplib when server closes connection

R. David Murray report at bugs.python.org
Wed Mar 20 21:48:30 CET 2013


New submission from R. David Murray:

If an SMTP server returns an error code and then closes the connection, smtplib will attempt to send an RSET command, which will then raise a socket error, which smtplib turns into a ServerDisconnectedError, thereby loosing the information about what error code the server actually returned.  While (except for code 421, as noted in issue 5713) a server doing this is technically out of spec with the RFC, it is a reality of the internet that it happens, and smtplib should handle it correctly.
  
Since the RSET is just to get the protocol back to a known starting state after an error, I believe the fix is to have an internal _rset method that wraps the RSET call in a try/except and just ignores any ServerDiscoonected error.  The library would then call this internally instead of the public API method.  If the library client continues on after the error code it gets back from calling an smtplib method that results in the server closing the connection, it will get the ServerDisconnected error the next time it tries to send a command to the server.  Thus the behavior change introduced here is just to allow commands that end with server disconnects to return an error code instead of an (otherwise mysterious and quite possibly currently-mishandled) ServerDisconnected error.  Since any existing code will already need to handle errors from commands sent to servers that *don't* disconnect, I believe that this is a safe fix from a backward compatibility standpoint.

----------
messages: 184793
nosy: r.david.murray
priority: normal
severity: normal
stage: needs patch
status: open
title: error responses from server are masked in smtplib when server closes connection
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17498>
_______________________________________


More information about the New-bugs-announce mailing list