Bug #9644
closedpyami-py3 DecodeError
0%
Description
python 3.8.5 reading holetemplate.mrc in leginon directory
cd leginon
from pyami import mrc mrc.readHeaderFromFile('holetemplate.mrc')
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/acheng/myami/pyami/mrc.py", line 838, in readHeaderFromFile h = f.read(1024) File "/usr/local/opt/python@3.8/bin/../Frameworks/Python.framework/Versions/3.8/lib/python3.8/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: invali
Updated by Anchi Cheng almost 4 years ago
mrc.read does work, though. Maybe this is not related to the myami-py3 changes.
Updated by Anchi Cheng almost 4 years ago
Same error on the mrc file 08mar13e_00010gr_00004sq_v02_00005hl.mrc in module/numextension/test
Updated by Jim Pulokas almost 4 years ago
This is definitely a side effect of pyami (particularly mrc.py) only being partially converted to py3. The code that parses the MRC header wants the file data to be read into python "bytes" objects instead of string objects. That was working fine when using function mrc.read() because it was already calling open() with file mode "rb". But two other calls to open() in mrc.py were still using mode "r" which defaults to "text" mode. I just fixed those "r" to "rb" in commit:043da6f6 on branch pyami-py3.
Updated by Anchi Cheng almost 4 years ago
- Status changed from Assigned to Closed
Tested. Working. Thank you.