Issue2331

classification
Title: "java.lang.IllegalArgumentException: Cannot create PyString with non-byte value" caused by non-ASCII characters in _socket.error.args[1] with unicode type
Type: Severity: normal
Components: Library Versions: Jython 2.7
Milestone: Jython 2.7.1
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: darjus Nosy List: Arfrever, darjus, zyasoft
Priority: Keywords:

Created on 2015-04-17.16:40:41 by Arfrever, last changed 2015-10-11.13:30:06 by darjus.

Messages
msg9877 (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) Date: 2015-04-17.16:40:40
>>> import _socket
>>> str(_socket.error(-1, "Sieć jest niedostępna"))
'[Errno -1] Sie\xc4\x87 jest niedost\xc4\x99pna'
>>> str(_socket.error(-1, u"Sieć jest niedostępna"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
        at org.python.core.PyString.<init>(PyString.java:64)
        at org.python.core.PyString.<init>(PyString.java:70)
        at org.python.core.Py.newString(Py.java:641)     
        at org.python.core.exceptions.EnvironmentError__str__(exceptions.java:280)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.python.core.exceptions$BoundStaticJavaMethod.__call__(exceptions.java:677)
        at org.python.core.PyObject.__call__(PyObject.java:445)
        at org.python.core.PyBaseExceptionDerived.__str__(PyBaseExceptionDerived.java:65)
        at org.python.core.PyString.str_new(PyString.java:164)
        at org.python.core.PyString$exposed___new__.new_impl(Unknown Source)
        at org.python.core.PyType.invokeNew(PyType.java:494)
        at org.python.core.PyType.type___call__(PyType.java:1690)
        at org.python.core.PyType.__call__(PyType.java:1680)
        at org.python.core.PyObject.__call__(PyObject.java:461)
        at org.python.core.PyObject.__call__(PyObject.java:465)
        at org.python.pycode._pyx4.f$0(<stdin>:1)
        at org.python.pycode._pyx4.call_function(<stdin>)
        at org.python.core.PyTableCode.call(PyTableCode.java:167)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1386)
        at org.python.core.Py.exec(Py.java:1430)
        at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)
        at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)
        at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:116)
        at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:62)
        at org.python.util.InteractiveConsole.push(InteractiveConsole.java:179)
        at org.python.util.InteractiveConsole._interact(InteractiveConsole.java:160)
        at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:120)
        at org.python.util.jython.run(jython.java:415)
        at org.python.util.jython.main(jython.java:142)

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value



This problem was originally noticed in test suite of pymongo-3.0 with non-English locales:
$ LC_ALL="en_US.UTF-8" jython2.7 -m unittest test.test_pooling.TestPoolMaxSize.test_max_pool_size_with_connection_failure
Got this failure java.net.SocketException: Network is unreachable during connect (<_realsocket at 0x2 type=client open_count=1 channel=[id: 0x18679e5f, 0.0.0.0/0.0.0.0:53816] timeout=1.0>)
Got this failure java.net.SocketException: Network is unreachable during connect (<_realsocket at 0x3 type=client open_count=1 channel=[id: 0xbd419398, 0.0.0.0/0.0.0.0:56258] timeout=1.0>)
.
----------------------------------------------------------------------
Ran 1 test in 2.184s

OK
$ LC_ALL="pl_PL.UTF-8" jython2.7 -m unittest test.test_pooling.TestPoolMaxSize.test_max_pool_size_with_connection_failure
Got this failure java.net.SocketException: Sieć jest niedostępna during connect (<_realsocket at 0x2 type=client open_count=1 channel=[id: 0x920a6791, 0.0.0.0/0.0.0.0:35129] timeout=1.0>)
E
======================================================================
ERROR: test_max_pool_size_with_connection_failure (test.test_pooling.TestPoolMaxSize)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_pooling.py", line 445, in test_max_pool_size_with_connection_failure
    for i in range(2):
  File "/usr/share/jython-2.7/Lib/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/usr/share/jython-2.7/Lib/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "pymongo/pool.py", line 509, in get_socket
    sock_info = self._get_socket_no_auth()
  File "pymongo/pool.py", line 543, in _get_socket_no_auth
    sock_info, from_pool = self.connect(), False
  File "pymongo/pool.py", line 482, in connect
    _raise_connection_failure(self.address, error)
  File "pymongo/pool.py", line 54, in _raise_connection_failure
    msg = '%s:%d: %s' % (host, port, error)
IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value

----------------------------------------------------------------------
Ran 1 test in 1.200s

FAILED (errors=1)

In last traceback, 'error' variable is instance of _socket.error with args[0] = -1 and args[1] = u'Unmapped exception: java.net.SocketException: Sie\u0107 jest niedost\u0119pna'.
msg10346 (view) Author: Darjus Loktevic (darjus) Date: 2015-10-11.06:58:29
Looks like the issue is not socket related:

>>> class TestError(IOError): pass

>>> str(TestError(u"Sieć jest niedostępna"))
asdfasdfasdf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0107' in position 3: ordinal not in range(128)


>>> str(TestError(1, u"Sieć jest niedostępna"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
	at org.python.core.PyString.<init>(PyString.java:64)
	at org.python.core.PyString.<init>(PyString.java:70)
	at org.python.core.Py.newString(Py.java:645)
	at org.python.core.exceptions.EnvironmentError__str__(exceptions.java:280)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.python.core.exceptions$BoundStaticJavaMethod.__call__(exceptions.java:677)
	at org.python.core.PyObject.__call__(PyObject.java:445)
	at org.python.core.PyBaseExceptionDerived.__str__(PyBaseExceptionDerived.java:65)
	at org.python.core.PyString.str_new(PyString.java:164)
	at org.python.core.PyString$exposed___new__.new_impl(Unknown Source)
	at org.python.core.PyType.invokeNew(PyType.java:494)
	at org.python.core.PyType.type___call__(PyType.java:1708)
	at org.python.core.PyType.__call__(PyType.java:1698)
	at org.python.core.PyObject.__call__(PyObject.java:461)
	at org.python.core.PyObject.__call__(PyObject.java:465)
	at org.python.pycode._pyx6.f$0(<stdin>:1)
	at org.python.pycode._pyx6.call_function(<stdin>)
	at org.python.core.PyTableCode.call(PyTableCode.java:167)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1403)
	at org.python.core.Py.exec(Py.java:1447)
	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)
	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)
	at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:116)
	at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:62)
	at org.python.util.InteractiveConsole.push(InteractiveConsole.java:181)
	at org.python.util.InteractiveConsole._interact(InteractiveConsole.java:162)
	at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:120)
	at org.python.util.jython.run(jython.java:419)
	at org.python.util.jython.main(jython.java:142)

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
msg10350 (view) Author: Darjus Loktevic (darjus) Date: 2015-10-11.13:30:06
This is now fixed and should be released for 2.7.1
https://github.com/jythontools/jython/commit/c61eaefb774cdb174472265d3c27fc5b87febd34

Thanks for the report!
History
Date User Action Args
2015-10-11 13:30:06darjussetstatus: open -> closed
assignee: darjus
messages: + msg10350
2015-10-11 06:58:30darjussetnosy: + darjus
messages: + msg10346
2015-04-20 20:54:22zyasoftsetmilestone: Jython 2.7.1
2015-04-17 16:40:41Arfrevercreate