smtplib STARTTLS problems

T

Tim Williams

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('(e-mail address removed)')
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('(e-mail address removed)')
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top