This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jamesls
Recipients Ilya.Kulakov, jamesls
Date 2019-04-12.00:26:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1555028764.56.0.125734545742.issue29288@roundup.psfhosted.org>
In-reply-to
Content
I ran into this as well also using the embedded distribution for windows (https://docs.python.org/3/using/windows.html#the-embeddable-package).

socket.getaddrinfo() will encode unicode hostnames using idna and trigger this error if you call this function in threads:

PS C:\Users\Administrator\Downloads\python-3.7.3-embed-amd64> cat .\repro.py
import threading
import socket


def task():
    try:
        socket.getaddrinfo('www.google.com', 443)
    except Exception as e:
        print("FAIL: %s" % e)
        raise


threads = []
for i in range(50):
    t = threading.Thread(target=task)
    threads.append(t)

for t in threads:
    t.start()

for t in threads:
    t.join()

print("DONE")


PS C:\Users\Administrator\Downloads\python-3.7.3-embed-amd64> .\python.exe .\repro.py
FAIL: unknown encoding: idna
FAIL: unknown encoding: idna
Exception in thread Thread-5:
Traceback (most recent call last):
  File "D:\obj\Windows-Release\37amd64_Release\msi_python\zip_amd64\threading.py", line 917, in _bootstrap_inner
  File "D:\obj\Windows-Release\37amd64_Release\msi_python\zip_amd64\threading.py", line 865, in run
  File ".\repro.py", line 7, in task
    socket.getaddrinfo('www.google.com', 443)
  File "D:\obj\Windows-Release\37amd64_Release\msi_python\zip_amd64\socket.py", line 748, in getaddrinfo
LookupError: unknown encoding: idna

FAIL: unknown encoding: idna
Exception in thread Thread-4:
Traceback (most recent call last):
  File "D:\obj\Windows-Release\37amd64_Release\msi_python\zip_amd64\threading.py", line 917, in _bootstrap_inner
  File "D:\obj\Windows-Release\37amd64_Release\msi_python\zip_amd64\threading.py", line 865, in run
  File ".\repro.py", line 7, in task
    socket.getaddrinfo('www.google.com', 443)
  File "D:\obj\Windows-Release\37amd64_Release\msi_python\zip_amd64\socket.py", line 748, in getaddrinfo
LookupError: unknown encoding: idna

Exception in thread Thread-6:
Traceback (most recent call last):
  File "D:\obj\Windows-Release\37amd64_Release\msi_python\zip_amd64\threading.py", line 917, in _bootstrap_inner
  File "D:\obj\Windows-Release\37amd64_Release\msi_python\zip_amd64\threading.py", line 865, in run
  File ".\repro.py", line 7, in task
    socket.getaddrinfo('www.google.com', 443)
  File "D:\obj\Windows-Release\37amd64_Release\msi_python\zip_amd64\socket.py", line 748, in getaddrinfo
LookupError: unknown encoding: idna

DONE


Confirmed that adding u''.encode('idna') fixes this issue.
History
Date User Action Args
2019-04-12 00:26:04jameslssetrecipients: + jamesls, Ilya.Kulakov
2019-04-12 00:26:04jameslssetmessageid: <1555028764.56.0.125734545742.issue29288@roundup.psfhosted.org>
2019-04-12 00:26:04jameslslinkissue29288 messages
2019-04-12 00:26:04jameslscreate