Skip to content

no relationship of type ... in collection error #204

Description

@cristian-codorean

Hi, I was trying python-docx with a .docx file which I got from a .doc file 'Saved as' a Strict Open XML Document with Microsoft Office Standard 2013. Unfortunately, when I'm trying to open the .docx file with python-docx, I get the error below. Does anybody have any idea what the problem is ?

Traceback (most recent call last):
  File "fillin_subrep_contract.py", line 39, in <module>
    fillin_contract_docx(sys.argv[1])
  File "fillin_subrep_contract.py", line 20, in fillin_contract_docx
    document = Document(wordfile)
  File "/var/tmp/mow/git/virtualenvs/webdev/lib/python2.7/site-packages/docx/api.py", line 25, in Document
    document_part = Package.open(docx).main_document_part
  File "/var/tmp/mow/git/virtualenvs/webdev/lib/python2.7/site-packages/docx/opc/package.py", line 108, in main_document_part
    return self.part_related_by(RT.OFFICE_DOCUMENT)
  File "/var/tmp/mow/git/virtualenvs/webdev/lib/python2.7/site-packages/docx/opc/package.py", line 127, in part_related_by
    return self.rels.part_with_reltype(reltype)
  File "/var/tmp/mow/git/virtualenvs/webdev/lib/python2.7/site-packages/docx/opc/rel.py", line 63, in part_with_reltype
    rel = self._get_rel_of_type(reltype)
  File "/var/tmp/mow/git/virtualenvs/webdev/lib/python2.7/site-packages/docx/opc/rel.py", line 116, in _get_rel_of_type
    raise KeyError(tmpl % reltype)
KeyError: u"no relationship of type 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' in collection"

Activity

  1. scanny commented on Sep 3, 2015

    @scanny
    Contributor

    I expect you'll see a difference in the .rels part of the document package. I expect it uses a different URI for the main document relationship. If you dump the .rels part with opc-diag you should be able to see it.

    If you do that on a regular Word document you get something like this:

    $ opc browse default.docx .rels
    <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
    <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
      <Relationship Id="x" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
      <Relationship Id="x" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
      <Relationship Id="x" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
      <Relationship Id="x" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail" Target="docProps/thumbnail.jpeg"/>
    </Relationships>

    The second relationship item is the one python-docx is looking for to start the "open" process. Apparently there's change in there somewhere when saving as strict OpenXML.

  2. cristian-codorean commented on Sep 3, 2015

    @cristian-codorean
    Author

    Thanks @scanny, my bad for using a 'Strict Open XML Document'. Re-generated my input document as a standard 'Word document' .docx and that seems to have fixed the problem.

  3. scanny commented on May 26, 2016

    @scanny
    Contributor

    Closing as resolved.

  4. wjchun commented on Apr 23, 2021

    @wjchun

    i have same issue , could you have other way using the python-docx to open the docx when saving as the strict open xml ?

  5. tungduonghgg123 commented on Dec 31, 2021

    @tungduonghgg123

    i have same issue , could you have other way using the python-docx to open the docx when saving as the strict open xml ?

    @scanny Hi, is there a way we can open this?

  6. Sicolas-Flamel commented on Sep 16, 2023

    @Sicolas-Flamel

    Hi you guys: try save AS a new file and read it..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions