pdbpp: TypeError: write() argument must be str, not bytes
Originally reported by: Aurélien Campéas (Bitbucket: auc, GitHub: auc)
#!python
File "C:\Anaconda2\envs\py3k\lib\site-packages\_pytest\pdb.py", line 109, in post_mortem
p.interaction(None, t)
File "C:\Anaconda2\envs\py3k\lib\site-packages\pdb.py", line 244, in interaction
self.print_stack_entry(self.stack[self.curindex])
File "C:\Anaconda2\envs\py3k\lib\site-packages\pdb.py", line 798, in print_stack_entry
print('[%d] >' % frame_index, file=self.stdout, end=' ')
File "C:\Anaconda2\envs\py3k\lib\codecs.py", line 377, in write
self.stream.write(data)
TypeError: write() argument must be str, not bytes
- Bitbucket: https://bitbucket.org/antocuni/pdb/issue/63
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 20
Commits related to this issue
- Fix ensure_file_can_write_unicode: use f.buffer Fixes https://github.com/antocuni/pdb/issues/63. — committed to pdbpp/pdbpp by blueyed 5 years ago
- Fix ensure_file_can_write_unicode: use f.buffer (#126) Fixes https://github.com/antocuni/pdb/issues/63. — committed to pdbpp/pdbpp by blueyed 5 years ago
- Fix ensure_file_can_write_unicode: use f.buffer (#126) Fixes https://github.com/antocuni/pdb/issues/63. — committed to blueyed/rebased-pdbpp by blueyed 5 years ago
I met the same error. After searching for a while, I follow the reference and work around by modifying codecs.py: self.stream.write(data) to self.stream.write(data.decode(‘utf-8’))
ref: https://stackoverflow.com/questions/21689365/python-3-typeerror-must-be-str-not-bytes-with-sys-stdout-write
Warning: I am okay with this modification. No guarantee for all cases using codes.py
I’m also having that problem on Python 3.5.2 using pdbpp 0.9.2 but it’s seems even more radical since it’s happening once I try to start pdb just after I imported it:
Yes, this is almost true.
Here is how to reproduce this error:
py.test
with locale set to some non-Unicode (this is the key change). Like this:LANG=C py.test mytest.py
I think this issue may not be caused by pdbpp (pdbpp is a great debugging tool ! thank you). It is probably caused by the python 3.5 as discussed in the reference above.
The failure case for me: I follow the “Docker image” part to build the docker image of the pytorch (https://github.com/pytorch/pytorch). And then I launch the docker. Running the commands below:
pip install pdbpp python import pdb pdb.set_trace()
And the error is shown below, which is not exactly the same as the original post. I then modify the codes.py to work around the problem.
Traceback (most recent call last): File “<stdin>”, line 1, in <module> File “/opt/conda/envs/pytorch-py35/lib/python3.5/bdb.py”, line 52, in trace_dispatch return self.dispatch_return(frame, arg) File “/opt/conda/envs/pytorch-py35/lib/python3.5/bdb.py”, line 93, in dispatch_return self.user_return(frame, arg) File “/opt/conda/envs/pytorch-py35/lib/python3.5/pdb.py”, line 290, in user_return self.message(‘–Return–’) File “/opt/conda/envs/pytorch-py35/lib/python3.5/pdb.py”, line 447, in message print(msg, file=self.stdout) File “/opt/conda/envs/pytorch-py35/lib/python3.5/codecs.py”, line 377, in write self.stream.write(data) TypeError: write() argument must be str, not bytes