[issue29288] Lookup Error while importing idna from a worker thread

2019-04-11 Thread James Saryerwinnie


James Saryerwinnie  added the comment:

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.

--
nosy: +James.Saryerwinnie

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29288] Lookup Error while importing idna from a worker thread

2017-01-16 Thread Ilya Kulakov

New submission from Ilya Kulakov:

See this post: https://github.com/kennethreitz/requests/issues/3578

The current workaround for requests is to have a no-op import somewhere in the 
code.

However, that doesn't really work for us: our python and stdlib are bundled by 
pyqtdeploy as in Qt resources system and we frequently see this error. On 
certain machines. Workaround that seems to work more reliably is a no-op look 
up via ''.encode('ascii').decode('idna').

--
components: Library (Lib)
messages: 285586
nosy: Ilya.Kulakov
priority: normal
severity: normal
status: open
title: Lookup Error while importing idna from a worker thread
versions: Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com