[Tutor] error: (10054, 'Connection reset by peer')
Ewald Ertl
ewald.ertl at hartter.com
Mon Jul 10 09:21:24 CEST 2006
Hello!
Grady Henry wrote:
> Here is a program that I wrote using the first example at 12.2.13
> Examples at the www.python.org <http://www.python.org> website,
>
> # Import smtplib for the actual sending function
> import smtplib
>
> # Import the email modules we'll need
> from email.MIMEText import MIMEText
>
> # Open a plain text file for reading. For this example, assume that
> # the text file contains only ASCII characters.
> fp = open('C:\Documents and Settings\User\Desktop\\text3.txt','rb')
> # Create a text/plain message
> msg = MIMEText(fp.read())
> fp.close()
>
> # me == the sender's email address
> # you == the recipient's email address
> msg['Subject'] = 'The contents of %s' % 'C:\Documents and
> Settings\User\Desktop\\text3.txt'
> msg['From'] = 'gwhjr at cox.net' <mailto:'gwhjr at cox.net'>
> msg['To'] = 'gwhjr at bigfoot.com' <mailto:'gwhjr at bigfoot.com'>
>
> # Send the message via our own SMTP server, but don't include the
> # envelope header.
> s = smtplib.SMTP()
> s.connect()
> s.sendmail(me, [you], msg.as_string())
> s.close()
>
> When I run the program using IDLE, I get the following message:
>
> Traceback (most recent call last):
> File "C:\Documents and Settings\User\Desktop\textsender.py", line 23, in ?
> s.connect()
> File "C:\Python24\lib\smtplib.py", line 307, in connect
> (code, msg) = self.getreply()
> File "C:\Python24\lib\smtplib.py", line 348, in getreply
> line = self.file.readline()
> File "C:\Python24\lib\socket.py", line 340, in readline
> data = self._sock.recv(self._rbufsize)
> error: (10054, 'Connection reset by peer')
>
> What does this mean, and how can I fix it?
You try to connect to your localhost on Port 25 for sending email. Because of
the Windows-Error 10054 'Connection reset by peer', I think you do not have an
email server running on your server.
Perhaps you can supply your email server in smtplib.SMTP().
Here is the pydoc of the init-Method:
__init__(self, host='', port=0, local_hostname=None)
Initialize a new instance.
If specified, `host' is the name of the remote host to which to
connect. If specified, `port' specifies the port to which to connect.
By default, smtplib.SMTP_PORT is used. An SMTPConnectError is raised
if the specified `host' doesn't respond correctly. If specified,
`local_hostname` is used as the FQDN of the local host. By default,
the local hostname is found using socket.getfqdn().
HTH
Ewald
More information about the Tutor
mailing list