"TypeError: can’t concat str to bytes" pops out at read(1)
statement in following code.
def __init__(self, infile):
self.infile = infile
while self.infile.read(1) != 'T':
pass
else:
.
infile is codecs.StreamReaderWriter object.
My system is Linux Debian, with python 3.11.4.
I am checking docs.python.org and other sites, but I have no idea where byte comes from.
I have changed infile to codecs.StreamReader object, but same error.
Any input will be appreciated.
2
Answers
Not quite an answer, but one step ahead. I tried to extract the simplest sample.
Following code works
While following code chokes, as the title reads
Both of
fce
andfse
are StreamReaderWriter object, one from file, the other from memory.Any suggestion will be appreciated.
When parsing your data you’re getting a StreamReaderWriter with binary data ([see docs here][1]) so either you’ll want to convert your check string to bytes eg.
notice the "b" inserted before your string – otherwise decode your byte type data eg.
This is assuming the encoding of your data is utf-8 but you may need to verify that is an accurate assumption.
[1]: https://docs.python.org/3/library/codecs.html#codecs.open