Skip to content

PyString with non-byte value while installing pip #20

Closed

Description

@ZhuBicen
  1. OS: Win 10
  2. Jython version: 2.7.1
  3. Java version: 1.8
  4. Run jython -m ensurepip
C:\Users\Memory>jython --version
Jython 2.7.1

C:\Users\Memory>java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

C:\Users\Memory>jython -m ensurepip
�[31mException:
Traceback (most recent call last):
  File "C:\Users\Memory\AppData\Local\Temp\tmplfy1lv\pip-9.0.1-py2.py3-none-any.whl\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\Users\Memory\AppData\Local\Temp\tmplfy1lv\pip-9.0.1-py2.py3-none-any.whl\pip\commands\install.py", line 270, in run
    global_options = options.global_options or []
  File "C:\Users\Memory\AppData\Local\Temp\tmplfy1lv\pip-9.0.1-py2.py3-none-any.whl\pip\basecommand.py", line 71, in _build_session
    retries=retries if retries is not None else options.retries,
  File "C:\Users\Memory\AppData\Local\Temp\tmplfy1lv\pip-9.0.1-py2.py3-none-any.whl\pip\download.py", line 329, in __init__
    self.headers["User-Agent"] = user_agent()
  File "C:\Users\Memory\AppData\Local\Temp\tmplfy1lv\pip-9.0.1-py2.py3-none-any.whl\pip\download.py", line 110, in user_agent
    if platform.system():
  File "C:\opt\jython2.7.1\Lib\platform.py", line 1396, in system
    return uname()[0]
  File "C:\opt\jython2.7.1\Lib\platform.py", line 1213, in uname
    machine = os.uname()[4]
IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value�[0m

Activity

  1. jeff5 commented on Nov 2, 2019

    @jeff5
    Member

    Does your host name contain non-ascii characters? I'm afraid that's a known problem in 2.7.1. You might like to try 2.7.2b2.

  2. ZhuBicen commented on Nov 6, 2019

    @ZhuBicen
    Author

    Does your host name contain non-ascii characters? I'm afraid that's a known problem in 2.7.1. You might like to try 2.7.2b2.

    Actually no. And I tried the 2.7.2b2 on Windows, it prompt, "Can't execute the specifed file". I don't know what is wrong. But the pip.exe which exist in the same directory works when pip --help

  3. leurnkim commented on Mar 10, 2020

    @leurnkim

    I have the same issue when script processing file names with non-english characters.

    java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
    org.python.core.PyString.(PyString.java:57)
    org.python.core.PyString.(PyString.java:70)
    org.python.core.PyString.(PyString.java:74)
    org.python.core.Py.newString(Py.java:647)

  4. jeff5 commented on Mar 12, 2020

    @jeff5
    Member

    We have tracked down most of the places this can happen, but there could be some left.

    One would need more detail to be of any help: the version of Jython and a fragment of Python that produces the effect is a minimum.

  5. jeff5 commented on Jun 4, 2020

    @jeff5
    Member

    Originally raised as https://github.com/jythontools/jython issue 153

  6. transferred this issue fromjython/frozen-mirroron Jun 4, 2020
  7. yogi1967 commented on Jun 19, 2022

    @yogi1967

    This same error happens when using print with a Java HashMap that contains Unicode characters. It can also occur with these HashMaps when using:

    “%s” %(theHashMap)
    Or
    print “something”, theHashMap

  8. jeff5 commented on Jun 25, 2022

    @jeff5
    Member

    This same error happens when using print with a Java HashMap that contains Unicode characters. It can also occur with these HashMaps when using:

    “%s” %(theHashMap) Or print “something”, theHashMap

    Since the problem crops up during formatting of a java.lang.String, I think this problem (but not necessarily the OP's) is the one investigated in #190.

  9. jeff5 commented on Jun 25, 2022

    @jeff5
    Member

    @yogi1967 : In fact, with HashMap and String keys or values, I only get this particular "non-byte value" error on v2.7.1, and v2.7.2 behaves sensibly, at least up to the point it tries to put the results on my console.

    Jython 2.7.2 (v2.7.2:925a3cc3b49d, Mar 21 2020, 10:03:58)
    [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_321
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from java.lang import String
    >>> from java.util import HashMap
    >>> h = HashMap()
    >>> h.put(String('\xce\xbb', 'utf-8'), 3)
    >>> h.put('g', String('\xce\xb3', 'utf-8'))
    >>> h
    {u'g': u'\u03b3', u'\u03bb': 3}
    >>> h.keySet()
    [g, λ]
    >>> print "%s" % h
    {u'g': u'\u03b3', u'\u03bb': 3}
    
  10. yogi1967 commented on Jun 26, 2022

    @yogi1967

    This code reproduces the problem...

    import jarray
    from java.lang import String
    from javax.swing import JOptionPane, JTextField, JPanel, JLabel
    from java.awt import GridLayout
    from java.nio.charset import StandardCharsets
    
    print "\n"*10
    print "-----"
    
    def myPopupInformationBox(_txtArray):
     pnl = JPanel(GridLayout(0, 1))
     for txt in _txtArray: pnl.add(JLabel(txt))
     JOptionPane.showMessageDialog(None, pnl, "DEMO ERROR", JOptionPane.INFORMATION_MESSAGE, None)
    
    txtArray = []
    
    txtArray.append("Normal text")
    
    myBytes = jarray.array([-25, -72, -67, -26, -108, -81, -27, -121, -70], 'b')
    newName2 = String(myBytes,StandardCharsets.UTF_8)
    txtArray.append(newName2)
    
    txtArray.append("More Normal text")
    
    # This works
    myPopupInformationBox(txtArray)
    
    print "---"
    
    # This works
    for txt in txtArray: print txt
    
    print "---"
    
    # This fails with: java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
    print txtArray
    
    

    it spits out:

    Traceback (most recent call last):
      File "<string>", line 36, in <module>
    java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
    	at org.python.core.PyString.<init>(PyString.java:57)
    	at org.python.core.PyString.<init>(PyString.java:70)
    	at org.python.core.PyString.<init>(PyString.java:74)
    	at org.python.core.PyObject.__repr__(PyObject.java:231)
    	at org.python.core.PyObject.__str__(PyObject.java:266)
    	at org.python.core.StdoutWrapper.printToFileWriter(StdoutWrapper.java:128)
    	at org.python.core.StdoutWrapper.print(StdoutWrapper.java:210)
    	at org.python.core.StdoutWrapper.println(StdoutWrapper.java:272)
    	at org.python.core.Py.println(Py.java:1905)
    	at org.python.pycode._pyx49.f$0(<string>:36)
    	at org.python.pycode._pyx49.call_function(<string>)
    	at org.python.core.PyTableCode.call(PyTableCode.java:173)
    	at org.python.core.PyCode.call(PyCode.java:18)
    	at org.python.core.Py.runCode(Py.java:1687)
    	at org.python.core.Py.exec(Py.java:1731)
    	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:268)
    	at com.moneydance.apps.md.view.gui.python.PythonRunner$2.run(PythonRunner.java:352)
    java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
    
    
  11. jeff5 commented on Jun 26, 2022

    @jeff5
    Member

    Sufficient to reproduce:

    from java.lang import String
    print [String(u"\u51fa")]
    

    I opened a new issue #192 for this. The circumstances are quite different from of this one. (Maybe need a better title.)

  12. changed the title [-]java.lang.IllegalArgumentException: Cannot create PyString with non-byte value[/-] [+]PyString with non-byte value while installing pip[/+] on Jun 26, 2022
  13. jeff5 commented on Jan 20, 2024

    @jeff5
    Member

    The same "non-byte string" error turns up in multiple contexts, quite a few of which we've fixed. The cause of the OP's remains obscure, but I don't think we learn anything by keeping this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions