Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gordio opened this issue Aug 10, 2017 · 12 comments
Closed

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

gordio opened this issue Aug 10, 2017 · 12 comments
Labels
Milestone

Comments

@gordio
Copy link

gordio commented Aug 10, 2017

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'
@ata2001
Copy link
Contributor

ata2001 commented Aug 15, 2017

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

@gordio
Copy link
Author

gordio commented Aug 15, 2017

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

@ata2001
Copy link
Contributor

ata2001 commented Aug 16, 2017

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.

@gordio
Copy link
Author

gordio commented Aug 16, 2017

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

Yep.

@ata2001
Copy link
Contributor

ata2001 commented Aug 16, 2017

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

@gordio
Copy link
Author

gordio commented Aug 16, 2017

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'>

@ata2001
Copy link
Contributor

ata2001 commented Aug 17, 2017

@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?

@gordio
Copy link
Author

gordio commented Aug 17, 2017

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

@thomasballinger
Copy link
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.

@slipsnip
Copy link

slipsnip commented Jun 9, 2020

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.

@thomasballinger
Copy link
Member

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

@sebastinas
Copy link
Contributor

This was fixed in b63051e.

sebastinas added a commit that referenced this issue Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants