[issue12578] Erratic socket.gaierror: [Errno 11004] when using smtplib

David Ward report at bugs.python.org
Sun Jul 17 13:39:39 CEST 2011

New submission from David Ward <d.j.ward.94 at gmail.com>:

When migrating from python 2.7.1 to 2.7.2 (or 3.2) I get unpredictable /erratic exceptions thrown on constucting smtplib.SMTP:

socket.gaierror: [Errno 11004] getaddrinfo failed 

Here is the call stack:

  File "**********\mail.py", line 41, in Mail
    server = smtplib.SMTP(MAILSERVER)
  File "c:\python27\lib\smtplib.py", line 250, in __init__
    (code, msg) = self.connect(host, port)
  File "c:\python27\lib\smtplib.py", line 306, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "c:\python27\lib\smtplib.py", line 284, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "c:\python27\lib\socket.py", line 380, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed

MAILSERVER is a local address. There are no known DNS issues on our local network. 

If I try to reduce the code to a small repro (e.g. sending mail in a loop or calling getaddrinfo), I cannot reproduce the problem.

This code had worked unchanged for many years and many previous python releases all the way back to 2.3.

Platform is Windows 7 x64, AMD64 build of python 2.7.2 (or 3.2).

Reverting back to 2.7.1 solves the problem.

components: Library (Lib)
messages: 140525
nosy: David.Ward
priority: normal
severity: normal
status: open
title: Erratic socket.gaierror: [Errno 11004] when using smtplib
type: behavior
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list