Project

General

Profile

Actions

Bug #9644

closed

pyami-py3 DecodeError

Added by Anchi Cheng about 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Start date:
12/07/2020
Due date:
% Done:

0%

Estimated time:
Affected Version:
Appion/Leginon 3.5
Show in known bugs:
No
Workaround:

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
Actions #1

Updated by Anchi Cheng about 4 years ago

  • Description updated (diff)
Actions #2

Updated by Anchi Cheng about 4 years ago

mrc.read does work, though. Maybe this is not related to the myami-py3 changes.

Actions #3

Updated by Anchi Cheng about 4 years ago

Same error on the mrc file 08mar13e_00010gr_00004sq_v02_00005hl.mrc in module/numextension/test

Actions #4

Updated by Jim Pulokas about 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.

Actions #5

Updated by Anchi Cheng about 4 years ago

  • Status changed from Assigned to Closed

Tested. Working. Thank you.

Actions

Also available in: Atom PDF