Socket error problem

David LeBlanc whisper at
Sun Jun 9 20:19:56 CEST 2002

> -----Original Message-----
> From: python-list-admin at
> [mailto:python-list-admin at]On Behalf Of Martin v. Lowis
> Sent: Sunday, June 09, 2002 4:04
> To: python-list at
> Subject: Re: Socket error problem
> "David LeBlanc" <whisper at> writes:
> > I have this problem on windows where socket.socket(...) keeps returning
> > 10022, 'Invalid argument'. It's actually dieing in the
> > poplib.POP3.__init__(...) method. I have verified that host is
> reasonable
> > ( or something like that ;)), and port is 110.
> >
> > If I use the test script in poplib.__main__(...) with the
> correct host, user
> > and password, all is well, but if I call it from this other program i'm
> > trying to get working I get the above error.
> >
> > I can't figure out what's wrong - any pointers?
> You make it sound like something impossible happens, so it is hard to
> recommend a solution (since clearly you are overlooking some piece of
> information, which you could not report for the very reason that you
> are overlooking it).
> I recommend to put a print statement immediately before the call to
> socket.socket inside poplib, to see what arguments it actually does
> pass to that call.
> Please report any information you gain by doing so.
> Regards,
> Martin

Martin and Steve;

In one part of the program it does this:

	serv = Pop3Server(adressaux, aux_username, aux_passwd, serverport)

and the args are: adressaux: aux_username: whisper aux_passwd:
password serverport: 110 (with aux_passwd changed to protect my innocence).

Then, it invokes POP3Server's connect method as:
def process (self, serv):
	"""Code actually executed by every thread except the main thread"""
	config = self.config # Very used
	log_index = 0
	if config.optnotlog:
		log_index= 0
		logAgent = None
		# logAgent collects stadistics and show them at the end (see
		# It has an entry for each server, which get indexed by log_index
		logAgent = self.logAgent
		log_index =, thread.get_ident())

	# If configured, send logging info to the system log
	# aprint() (see takes care of this automatically
#     if  config.optsyslog:
#     	import syslog
#     	syslog.openlog("Animail", 0, syslog.LOG_MAIL)

	messages = 0
	aprint(_("Trying to connect (%s)") % serv.alias, general.YELLOW)
	v = serv.connect()
	aprint (_('connected!\n'), serv.alias, general.YELLOW)
	aprint(_("Authenticating (%s)") % serv.alias, general.YELLOW)
except smtplib.SMTPException, x:
	self.error_msg("SMTP Error (%s): " % serv.adress, x, log_index)

except socket.error, x:
	self.error_msg(_("Connection error (%s): ") %, x, log_index)

except poplib.error_proto, x:
	self.error_msg(_("Protocol Error (%s): ") % serv.adress, x, log_index)
The general.* constant references are to colorize the output which is turned
off but still results in the "31" in the connection error line in the
program output below. NOTE: I didn't write this code, so I have no idea why
it's returning the username in the socket.error instead of the host. FWIW,
this code is running in a thread, but there is only one thread trying to get

POP3Server's connect method:
    def connect(self):
        self.lmsg = []
        if self.adress == '':
            raise ConfigError, _("Server address not given!!")

        if self.ssl:
            import popslib
            self.objpop = popslib.POP3S(self.adress, self.port)
            self.objpop = poplib.POP3(self.adress, self.port)
        welcome = self.objpop.getwelcome()
        if self.protocol == 'APOP':
            lwelcome = welcome.split()
            self.timestamp = lwelcome[0]
        return welcome
        # end if
    # end def connect
"self.ssl" is false, so objpop becomes a poplib.POP3
"self.protocol is POP3, so the APOP stuff isn't executed.

At this point, self.adress and self.port are and 110

In poplib.POP3.__init__(...) they are also and 110
    def __init__(self, host, port = POP3_PORT): = host
        self.port = port
        msg = "getaddrinfo returns an empty list"
        self.sock = None
        for res in socket.getaddrinfo(, self.port, 0,
            af, socktype, proto, canonname, sa = res
                self.sock = socket.socket(af, socktype, proto)
            except socket.error, msg:
                if self.sock:
                self.sock = None
        if not self.sock:
            raise socket.error, msg
        self.file = self.sock.makefile('rb')
        self._debugging = 0
        self.welcome = self._getresp()

The output of the program is:
K:\tmp\animail>animail -v
Opening Config file: c:/user/dave/.animail/animailrc

Trying to connect (
("Connection error (whisper):  (10022, 'Invalid argument')", 31)

####### Operation summary #######

Sun Jun 09 11:01:04 2002

--- Server:

* Total messages: 0
* Total volume on server: 0.00 Bytes
* Filtered messages: 0
* Downloaded messages: 0
* Postergated messages: 0
* Incidents:
        -Connection error (whisper):  (10022, 'Invalid argument')

Dave LeBlanc
Seattle, WA USA

More information about the Python-list mailing list