Socket error problem
David LeBlanc
whisper at oz.net
Sun Jun 9 14:19:56 EDT 2002
> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Martin v. Lowis
> Sent: Sunday, June 09, 2002 4:04
> To: python-list at python.org
> Subject: Re: Socket error problem
>
>
> "David LeBlanc" <whisper at oz.net> 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
> > (mymail.myisp.net 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: mail.oz.net 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
else:
# logAgent collects stadistics and show them at the end (see logger.py)
# It has an entry for each server, which get indexed by log_index
logAgent = self.logAgent
log_index = logAgent.new(serv.alias, thread.get_ident())
# If configured, send logging info to the system log
# aprint() (see general.py) takes care of this automatically
# if config.optsyslog:
# import syslog
# syslog.openlog("Animail", 0, syslog.LOG_MAIL)
try:
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)
serv.auth()
.
.
.
except smtplib.SMTPException, x:
self.error_msg("SMTP Error (%s): " % serv.adress, x, log_index)
self.__exit_thread()
except socket.error, x:
self.error_msg(_("Connection error (%s): ") % serv.name, x, log_index)
self.__exit_thread()
except poplib.error_proto, x:
self.error_msg(_("Protocol Error (%s): ") % serv.adress, x, log_index)
self.__exit_thread()
----------------------
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
mail.
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)
else:
self.objpop = poplib.POP3(self.adress, self.port)
welcome = self.objpop.getwelcome()
if self.protocol == 'APOP':
lwelcome = welcome.split()
lwelcome.reverse()
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 mail.oz.net and 110
In poplib.POP3.__init__(...) they are also mail.oz.net and 110
def __init__(self, host, port = POP3_PORT):
self.host = host
self.port = port
msg = "getaddrinfo returns an empty list"
self.sock = None
for res in socket.getaddrinfo(self.host, self.port, 0,
socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
self.sock = socket.socket(af, socktype, proto)
self.sock.connect(sa)
except socket.error, msg:
if self.sock:
self.sock.close()
self.sock = None
continue
break
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 (mail.oz.net)
("Connection error (whisper): (10022, 'Invalid argument')", 31)
####### Operation summary #######
Sun Jun 09 11:01:04 2002
--- Server: mail.oz.net
* 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