artefactual-labs / mets-reader-writer

Library to parse and create METS files, especially for Archivematica.
https://mets-reader-writer.readthedocs.io
GNU Affero General Public License v3.0
20 stars 13 forks source link

metsrw.METSDocument.fromfile fails over undefined "root" #36

Closed nemobis closed 5 years ago

nemobis commented 6 years ago

This METS file is at least well formed according to xmllint, I think it should not fail in the amdSec stage already: A.ALF.ANT.R.091_METS.xml.gz

>>> mets = metsrw.METSDocument.fromfile('A.ALF.ANT.R.091_METS.xml')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/metsrw/mets.py", line 437, in fromfile
    i._fromfile(path)
  File "/usr/lib/python2.7/site-packages/metsrw/mets.py", line 431, in _fromfile
    self._parse_tree(self.tree)
  File "/usr/lib/python2.7/site-packages/metsrw/mets.py", line 414, in _parse_tree
    tree, structMap, normative_parent_elem=normative_struct_map)
  File "/usr/lib/python2.7/site-packages/metsrw/mets.py", line 291, in _parse_tree_structmap
    tree, elem, normative_parent_elem=normative_elem)
  File "/usr/lib/python2.7/site-packages/metsrw/mets.py", line 298, in _parse_tree_structmap
    self._add_amdsecs_to_fs_entry(fptr.amdids, fs_entry, tree)
  File "/usr/lib/python2.7/site-packages/metsrw/mets.py", line 390, in _add_amdsecs_to_fs_entry
    amdsec = metadata.AMDSec.parse(amdsec_elem)
  File "/usr/lib/python2.7/site-packages/metsrw/metadata.py", line 59, in parse
    if root.tag != utils.lxmlns('mets') + 'amdSec':
AttributeError: 'NoneType' object has no attribute 'tag'

Python 2.7 on Fedora 25, metsrw installed via pip (Downloading metsrw-0.2.0-py2.py3-none-any.whl (62kB)).

ross-spencer commented 5 years ago

Hi @nemobis I have logged a similar issue recently, and referenced this one on the github.com/archivematica/issues forum as issue-336. I am closing this as a duplicate, and it will remain in our primary GitHub issues repo. If you feel the other ticket is substantially different, or could do with more information then please feel free to re-open this, or add your comments on #636 as well.

nemobis commented 5 years ago

Ross Spencer, 09/04/19 09:11:

If you feel the other ticket is substantially different, or could do with more information then please feel free to re-open this, or add your comments on #636 as well.

Thank you for the update! I will the next time I use this, if I encounter some problem.