rpt2csv.py icon indicating copy to clipboard operation
rpt2csv.py copied to clipboard

TypeError: a bytes-like object is required, not 'str' on line 53

Open Austin1 opened this issue 8 years ago • 3 comments

I assume it has something to do with using Python 3.6, but I'm getting the error in the subject line when executing. Stackexchange says we are reading it as a binary and it needs to be read as a ascii. See https://stackoverflow.com/questions/33054527/python-3-5-typeerror-a-bytes-like-object-is-required-not-str-when-writing-t

I'm not a python developer (or any developer) so I don't know how to fix, but thought someone else might see this and have an interest in tweaking to fix.

Austin1 avatar Sep 03 '17 22:09 Austin1

I'm not certain this is the full fix, but following the advice in that link but I tried replacing line 52:

with open(sys.argv[2],'wb') as outputFile:`

with the line

with open(sys.argv[2],'w') as outputFile:

It seems to be that the 'wb' argument was trying to write in bytes, when the link is suggesting we'd rather just write directly in text with 'w'.

jagman88 avatar Oct 03 '17 21:10 jagman88

Yes, this is an issue with Python major versions. I wrote this with 2.7. Honestly I didn't expect that people would find it that useful, but if it helps I can move 2.7 to its own branch and make master python 3 compatible.

If I recall correctly @jagman88 is right about the open statement needing to change, but there was another issue with reading UTF-8 files with byte-order-marks. It looks like I at some point upgraded to Python 3 but never committed the changes.

I'll add another note when this is resolved.

ghost avatar Oct 04 '17 00:10 ghost

@jagman88 @Austin1 - I pushed up some changes, but I don't have an RPT file handy to test with. Give it a shot.

ghost avatar Oct 04 '17 01:10 ghost