smtplib STARTTLS problems

Tim Williams listserver at tdw.net
Tue Apr 12 12:20:07 EDT 2005


I have a working SMTP client that I need to add TLS capability to,    I
absolutely need the client to timeout within a specified time,  but when I
use the sock.timeout() line it freezes the reading of chars from SSLFakeFile
used during TLS  instead of timing out the client connection.    I am
working from my own hacked version of smtplib,  but can demonstrate the
problem using the standard module (Python 2.3.4).   Can anyone suggest a
workaround hack that I can impliment in my own version of smtplib ??

Thanks in advance

Working version =

import smtplib as mx
s=mx.SMTP('e32.co.us.ibm.com')
s.set_debuglevel(1)
s.ehlo('x')
resp, null =  s.starttls()
if resp == 220:
    s.ehlo('x')
s.mail('me at mydomain.com')
s.quit()



Non-Working version =

import smtplib as mx
s=mx.SMTP('e32.co.us.ibm.com')
s.sock.settimeout(20)
s.set_debuglevel(1)
s.ehlo('x')
resp, null =  s.starttls()
if resp == 220:
    s.ehlo('x')
s.mail('me at mydomain.com')
s.quit()

Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "tls2.py", line 8, in ?
    print s.ehlo('x')
  File "C:\Python23\lib\smtplib.py", line 404, in ehlo
    (code,msg)=self.getreply()
  File "C:\Python23\lib\smtplib.py", line 356, in getreply
    line = self.file.readline()
  File "C:\Python23\lib\smtplib.py", line 160, in readline
    chr = self.sslobj.read(1)
sslerror: The read operation timed out






More information about the Python-list mailing list