views:

25

answers:

1

I have written a python script which binds to a socket like this:

from socket import *
addr = (unicode(), 11111)
mySocket = socket(AF_INET, SOCK_STREAM)
mySocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
mySocket.bind(addr)

I package this script with py2exe using setup.py with the following options:

setup(
    console=["myProgram.py"],
    options = {"py2exe": {"compressed": 1,
                      "optimize": 2,
                      "bundle_files": 1,
                      "excludes": ["w9xpopen.exe"],
                      "packages": ["encodings","codecs"],
                          }},
    zipfile = None)

Under Python 2.5 this works fine. However, when I package the source under python 2.6, I get the following error:

   Traceback (most recent call last):
   File "Mod_CommsServ.pyo", line 201, in __init
    File "<string>", line 1, in bind
    LookupError: unknown encoding: idna

As you can see, I already included encodings for py2exe, but the executable still is not able to resolve 'idna'. Can anybody help me?

A: 

Because you pass a unicode string as hostname, python2.6 assumes "IDNA" (Internationalized Domain Names in Applications) needs to take place.

Just use

addr = ('', 11111)

in stead, unless you have very good reasons to require IDNA support.

Ivo van der Wijk
I used that before changing it to unicode. But then python would complain about not getting unicode, but str with null values.
Bertolt