Re: "AssertionError Only AF_INET sockets": Is this an normal error?
Alexandru Popescu ☀ <the.mindstorm.mailinglist <at> gmail.com>
2009-09-01 09:35:07 GMT
On Tue, Sep 1, 2009 at 11:12 AM, Alan Kennedy<jython-dev <at> xhaus.com> wrote:
> [Alexandru]
>>> I am wondering if the following trace is a normal/expected one:
>
> [..snip..]
>
>>> assert family == AF_INET, "Only AF_INET sockets are currently
>>> supported on jython"
>>> AssertionError: Only AF_INET sockets are currently supported on jython
>
> [Marc]
>> I came across this very assertion this afternoon. I changed 'localhost' to
>> '127.0.0.1' and got back to my code without thinking long enough to file a
>> bug report.
>> Perhaps that will work (as a workaround) in your case?
>> (I'm not sure when this happened, but it's recent; my "locahost" code in
>> question certainly used to work — I'm on Mac OS X 10.6, 64 bit Java 6).
>
> That assertion is in there to ensure that people don't pass AF_INET6
> as a parameter when opening sockets, since AF_INET6 family sockets is
> not currently supported.
>
> Sockets are usually opened like this
>
> import socket
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>
> If you attempt to open an IPV6 socket, with AF_INET6, then you'll get
> the assertion error above.
>
> The address you're using is possibly obtained from
> socket.getaddrinfo(), using a call something like this
>
> for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
> af, socktype, proto, canonname, sa = res
>
> Try examining the results that come back from getaddrinfo for your
> host/port combination: I expect that you are being returned an
> AF_INET6 address.
>
> The way to retrieve only AF_INET results from getaddrinfo is to pass
> AF_INET as the family parameter, e.g.
>
> for res in socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM):
> af, socktype, proto, canonname, sa = res
>
> But I note that it is common in python library modules to simply hard
> code the value of "0" as the family parameter, meaning that results
> from all families are acceptable, i.e. AF_INET and AF_INET6. Therre
> are examples of that in ftplib, httplib, poplib, smtplib, and
> telnetlib; I'm not sure about urllib/urllib2, and don't have time to
> investigate right now.
>
> A simple workaround, as Marc discovered, is to use a raw IPV4 address
> instead of the hostname, i.e. "127.0.0.1", which will ensure that you
> only get AF_INET results back from getaddrinfo.
>
> I'll look at this some more later.
>
> Alan.
>
Thanks a lot for the extensive explanation (I must confess that I'm
not sure I understand all the details).
Now, I don't actually need a workaround for it, but I wasn't wondering
if this is a limitation, bug, or something else.
./alex
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users