[Pythonmac-SIG] socket code works on Win32 but not Mac :-(

Nehemiah Dacres vivacarlie at gmail.com
Thu Jan 15 18:14:49 CET 2009


temporary answer

 http://www.artima.com/forums/flat.jsp?forum=181&thread=113874

On Thu, Jan 15, 2009 at 4:27 AM, Ranec <python-mac at cemery.org.uk> wrote:

> Dear All,
>
> I'm writing a Python FOSS application and am *very* keen to keep it
> platform agnostic.
>
> I don't own a Mac, but have access to some sympathetic Mac owners. :-)
>
> The following code works just fine under Windows XP and Vista but not on
> MacOS X (currently no idea what version, though Python is 2.5.?). Any
> thoughts?
>
> def get_my_ip_address():
>    ret=None
>    try:
>        s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>        s.connect(('google.com', 0))
>        sn=s.getsockname()
>        if sn:
>            ret=sn[0]
>    except socket.error, e:
>        hn=socket.gethostname()
>        ret=socket.gethostbyname(hn)
>    return ret
>
> produces the stack:
>
> Traceback (most recent call last):
>  File "./sarnie_client.py", line 181, in get_my_ip_address
>    s.connect(('google.com', 0))
>  File "<string>", line 1, in connect
> socket.error: (49, "Can't assign requested address")
>
> My application has been given firewall rights accept connections from
> the Internet. Is there perhaps anything else that I should configure?
>
> TIA
>
> -R
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
>



-- 

"lalalalala! it's not broken because I can use it"

http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20090115/c33021c7/attachment.htm>


More information about the Pythonmac-SIG mailing list