Skip to content

TypeError: a bytes-like object is required, not 'str' #700

Closed

Description

@gordio

You may understand…

(venv) Ori@gordio ~/Development/python/sk-numbers
❱bpython
bpython version 0.16 on top of Python 3.6.2 /Users/gordio/Development/python/sk-numbers/venv/bin/python3
>>> import matplotlib.pyplot as plt
>>> plt.plot([1,2,2.5,3])
[<matplotlib.lines.Line2D object at 0x10cd60320>]
>>> plt.show()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    plt.show()
  File "/Users/gordio/Development/python/sk-numbers/venv/lib/python3.6/site-pack
ages/matplotlib/pyplot.py", line 253, in show
    return _show(*args, **kw)
  File "/Users/gordio/Development/python/sk-numbers/venv/lib/python3.6/site-pack
ages/itermplot/__init__.py", line 131, in show
    figmanager.show()
  File "/Users/gordio/Development/python/sk-numbers/venv/lib/python3.6/site-pack
ages/itermplot/__init__.py", line 275, in show
    imgcat(data.getbuffer(), fn)
  File "/Users/gordio/Development/python/sk-numbers/venv/lib/python3.6/site-pack
ages/itermplot/__init__.py", line 115, in imgcat
    sys.stdout.write(buf)
  File "/Users/gordio/Development/python/sk-numbers/venv/lib/python3.6/site-pack
ages/bpython/curtsiesfrontend/coderunner.py", line 213, in write
    self.on_write(s, *args, **kwargs)
  File "/Users/gordio/Development/python/sk-numbers/venv/lib/python3.6/site-pack
ages/bpython/curtsiesfrontend/repl.py", line 1128, in send_to_stdout
    lines = output.split('\n')
TypeError: a bytes-like object is required, not 'str'

Activity

  1. ata2001 commented on Aug 15, 2017

    @ata2001
    Contributor

    Hi @gordio! Could you check, whether the issue is still present with the latest (0.17) release?

  2. gordio commented on Aug 15, 2017

    @gordio
    Author

    @ata2001 yep, still exist on bpython version 0.18.dev2 on top of Python 3.6.2

  3. ata2001 commented on Aug 16, 2017

    @ata2001
    Contributor

    So if I understand it correctly, this software is trying to write binary data to the stdout to display an image? @thomasballinger We could put a try except structure in send_to_stdout, if it's really needed.

  4. gordio commented on Aug 16, 2017

    @gordio
    Author

    this software is trying to write binary data to the stdout to display an image

    Yep.

  5. ata2001 commented on Aug 16, 2017

    @ata2001
    Contributor

    @gordio Please apply this patch, run bpython with the -L option, reproduce the error, and post the contents of bpython.log!

  6. gordio commented on Aug 16, 2017

    @gordio
    Author

    bpython.log!

    popping an event! (1502927491.0099788, <RefreshRequestEvent for -0.0037224292755126953 seconds from now>) []
    <class 'str'>
    received ASAP refresh request event
    <class 'str'>
    received ASAP refresh request event
    <class 'bytes'>
    
  7. ata2001 commented on Aug 17, 2017

    @ata2001
    Contributor

    @gordio Thank you! The error comes from bpython trying to split the image with a string as a separator.

    Is there any way, I could test it on a GNU/linux system?

  8. gordio commented on Aug 17, 2017

    @gordio
    Author

    I don't know. But you can install https://github.com/daleroberts/itermplot and test.

  9. thomasballinger commented on Feb 14, 2018

    @thomasballinger
    Member

    Hmmmmm so we ought to be allowing bytes to pass through huh? This actually may be related to a unicode width-predicting issue I'm hoping to look at: there are some things like escape codes and binary image data that make predicting what the terminal will look like difficult for bpython, so maybe we should just be printing and then seeing where the cursor is.

    That said, I think the odds of this being supported in curtsies are pretty low, it seems like it could interfere with the terminal-rewriting rewind behavior I'm unreasonably fond of.

  10. slipsnip commented on Jun 9, 2020

    @slipsnip

    Should I open a new issue or contribute here, I get this error when trying to use the click library. It happens if I first import click and then result = click.prompt('anytext') but does not happen if I do this exact same step in the native python 3.8 repl. Let me know if a new issue is needed or if I should add any more information here.

  11. thomasballinger commented on Jul 11, 2020

    @thomasballinger
    Member

    @slipsnip Please open a new issue, that sounds easier to address (and more urgent)

  12. added this to the release-0.22 milestone on Oct 15, 2021
  13. sebastinas commented on Oct 15, 2021

    @sebastinas
    Contributor

    This was fixed in b63051e.

  14. added a commit that references this issue on Oct 15, 2021
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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions