Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting to Jython a Python 3.5 project - UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character

My final purpose is to convert a running Python project to Jython interpreter because some java API's are going to be added.

Details:

  • The latest Jython is 2.7
  • The project I have is runnable with Python 3.5

So I took the following approach:

First thing was to convert my project to Python 2.7 utilizing the future module and pasteurize executable. This step was done successfully.

Second thing is to convert the Python 2.7 project to a Jython 2.7 Project. Switching the interpreter at Eclipse mars, the following error was indicated:

console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.

To workaround it, the solution from this post was utilized by passing the encoding argument -Dpython.console.encoding=UTF-8 to the java VM according to figure below: enter image description here

Thumbs were up when trying to run again. But unfortunately here, the error shown below just appeared. As I don't plan to change any imported module if there's no need to do so, I decided to ask help here.

pydev debugger: starting (pid: 4216)
Traceback (most recent call last):
  File "C:\Users\souzadan\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydevd.py", line 2364, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Users\souzadan\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydevd.py", line 1784, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Users\souzadan\FirmwareDevTools\Workspaces\Eclipse\aPythonWorkspace\aPythonProject\aPythonFolder\aPythonFile.py", line 7, in <module>
    standard_library.install_aliases()
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\standard_library\__init__.py", line 465, in install_aliases
    from future.backports.urllib import request
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\urllib\request.py", line 96, in <module>
    from future.backports import email
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\email\__init__.py", line 16, in <module>
    from future.utils import surrogateescape
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 167, in <module>
    FS_ENCODING = 'ascii'; fn = b('[abc\xff]'); encoded = u('[abc\udcff]')
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 25, in u
    return text.decode('unicode_escape')
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 297, in _MainThread__exitfunc
    t.join()
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 128, in join
    raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
Error in sys.exitfunc:
Traceback (most recent call last):
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 297, in _MainThread__exitfunc
    t.join()
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 128, in join
    raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread

Running Jython through the command line results in a shorter error log:

Traceback (most recent call last):
  File "somePythonCode.py", line 7, in <module>
    standard_library.install_aliases()
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\standard_library\__init__.py", line 465, in install_aliases
    from future.backports.urllib import request
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\urllib\request.py", line 96, in <module>
    from future.backports import email
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\email\__init__.py", line 16, in <module>
    from future.utils import surrogateescape
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 167, in <module>
    FS_ENCODING = 'ascii'; fn = b('[abc\xff]'); encoded = u('[abc\udcff]')
  File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 25, in u
    return text.decode('unicode_escape')
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character

Does anybody have a clue of how to solve this error in the most elegant manner?

A bug was created at Jython.org with a critical severity because many people are utilizing already the latest Python modules and interpreter. And they might want to add Java functionality to their code. So they would basically have to take same path as I did. Backporting the project to Python 2.7 then to Jython 2.7 subsequentely.

At python-future a feature request bug was recorded too.

like image 976
Prophet Daniel Avatar asked Nov 10 '15 13:11

Prophet Daniel


1 Answers

Relying on py4j, as Roland Smith suggests, would be a good approach for porting your app to a JVM environment.

like image 150
J_H Avatar answered Oct 20 '22 02:10

J_H