Title: Unable to read docx containing pictures linking to internal bookmarks: KeyError: "There is no item named 'word/#MyBookmark' in the archive" · Issue #902 · python-openxml/python-docx · GitHub
Open Graph Title: Unable to read docx containing pictures linking to internal bookmarks: KeyError: "There is no item named 'word/#MyBookmark' in the archive" · Issue #902 · python-openxml/python-docx
X Title: Unable to read docx containing pictures linking to internal bookmarks: KeyError: "There is no item named 'word/#MyBookmark' in the archive" · Issue #902 · python-openxml/python-docx
Description: The document below contains a picture with a hyperlink to an internal bookmark. PictureBookmarks.docx (The very last picture links to the very first Heading1) I get this error message when reading the file using python-docx: KeyError: "T...
Open Graph Description: The document below contains a picture with a hyperlink to an internal bookmark. PictureBookmarks.docx (The very last picture links to the very first Heading1) I get this error message when reading ...
X Description: The document below contains a picture with a hyperlink to an internal bookmark. PictureBookmarks.docx (The very last picture links to the very first Heading1) I get this error message when reading ...
Opengraph URL: https://github.com/python-openxml/python-docx/issues/902
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unable to read docx containing pictures linking to internal bookmarks: KeyError: \"There is no item named 'word/#MyBookmark' in the archive\"","articleBody":"The document below contains a picture with a hyperlink to an internal bookmark.\r\n\r\n[PictureBookmarks.docx](https://github.com/python-openxml/python-docx/files/5638403/PictureBookmarks.docx) (The very last picture links to the very first Heading1)\r\n\r\nI get this error message when reading the file using python-docx: `KeyError: \"There is no item named 'word/#MyBookmark' in the archive\"`\r\n\r\n## Stack trace\r\n```\r\n# Command\r\nself.document = Document(document)\r\n\r\n# Trace (from pytest)\r\n..\\..\\..\\..\\..\\python-docx\\docx\\api.py:32: in Document\r\n document_part = Package.open(docx).main_document_part\r\n..\\..\\..\\..\\..\\python-docx\\docx\\opc\\package.py:117: in open\r\n pkg_reader = PackageReader.from_file(pkg_file)\r\n..\\..\\..\\..\\..\\python-docx\\docx\\opc\\pkgreader.py:37: in from_file\r\n phys_reader, pkg_srels, content_types\r\n..\\..\\..\\..\\..\\python-docx\\docx\\opc\\pkgreader.py:74: in _load_serialized_parts\r\n for partname, blob, reltype, srels in part_walker:\r\n..\\..\\..\\..\\..\\python-docx\\docx\\opc\\pkgreader.py:119: in _walk_phys_parts\r\n for partname, blob, reltype, srels in next_walker:\r\n..\\..\\..\\..\\..\\python-docx\\docx\\opc\\pkgreader.py:114: in _walk_phys_parts\r\n blob = phys_reader.blob_for(partname)\r\n..\\..\\..\\..\\..\\python-docx\\docx\\opc\\phys_pkg.py:109: in blob_for\r\n return self._zipf.read(pack_uri.membername)\r\nC:\\...\\lib\\zipfile.py:1337: in read\r\n with self.open(name, \"r\", pwd) as fp:\r\nC:\\...\\lib\\zipfile.py:1375: in open\r\n zinfo = self.getinfo(name)\r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \r\nself = \u003czipfile.ZipFile filename='C:\\\\...\\\\PictureBookmarks.docx' mode='r'\u003e, name = 'word/#MyBookmark'\r\n\r\n def getinfo(self, name):\r\n \"\"\"Return the instance of ZipInfo given 'name'.\"\"\"\r\n info = self.NameToInfo.get(name)\r\n if info is None:\r\n raise KeyError(\r\n\u003e 'There is no item named %r in the archive' % name)\r\nE KeyError: \"There is no item named 'word/#MyBookmark' in the archive\"\r\n```\r\n\r\n# How to recreate\r\nThis is achieved by:\r\n1. Adding a picture to the Word file\r\n2. Right-click =\u003e Link\r\n3. Add link to any internal bookmark.\r\n\r\nThen the hyperlink ends up like this, notice the `a:hlinkClick` relationship ID:\r\n\r\n```\r\n \u003cw:drawing\u003e\r\n \u003cwp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\" wp14:anchorId=\"2A30E332\" wp14:editId=\"3F2B5F70\"\u003e\r\n (...)\r\n \u003ca:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"\u003e\r\n \u003ca:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"\u003e\r\n \u003cpic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"\u003e\r\n \u003cpic:nvPicPr\u003e\r\n \u003cpic:cNvPr id=\"28\" name=\"Picture 28\" descr=\"(...)\"\u003e\r\n \u003ca:hlinkClick r:id=\"rId21\"/\u003e\r\n \u003c/pic:cNvPr\u003e\r\n \u003cpic:cNvPicPr/\u003e\r\n \u003c/pic:nvPicPr\u003e\r\n \u003cpic:blipFill\u003e\r\n (...)\r\n \u003c/pic:blipFill\u003e\r\n (...)\r\n \u003c/pic:pic\u003e\r\n \u003c/a:graphicData\u003e\r\n \u003c/a:graphic\u003e\r\n \u003c/wp:inline\u003e\r\n \u003c/w:drawing\u003e\r\n```\r\n\r\nNow, in `word/_rels/document.xml.rels`, we get:\r\n\r\n```\r\n \u003cRelationship Id=\"rId21\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink\" Target=\"#MyBookmark\"/\u003e\r\n```\r\n\r\nThis item bugs python-docx for me. I'll admit I'm using a 2.5-year-old version of the package, since I needed to modify stuff for my own usecase, so I am not sure whether this has been fixed after that. I was looking for whether this had been solved somehow, and it seems it is very much related to this issue.\r\n\r\n# Investigation\r\nI see in the `pkgreader` that the `target_mode` can be used to identify external targets, and that external targets receive special treatment to avoid such zipfile issues. External targets are recognized in the relationship file for e.g. hyperlinks to web sites, and add a `Target` attribute to the `\u003cRelationship\u003e` object.\r\n\r\nFrom what I gather, `RT.HYPERLINK` elements that have a `Target` starting with `#` should be treated specially - like some sort of internal bookmark relationship (or similar).","author":{"url":"https://github.com/aorsten","@type":"Person","name":"aorsten"},"datePublished":"2020-12-03T19:11:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/902/python-docx/issues/902"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b8050fe0-3867-ff8c-5494-89bef60e7105 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC0C:35E3DA:2D9D053:3C0B653:696DB1A2 |
| html-safe-nonce | 72278b3baf3cca2c9038a53669f29a26e66555e6212074bbba91296f824974f3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzBDOjM1RTNEQToyRDlEMDUzOjNDMEI2NTM6Njk2REIxQTIiLCJ2aXNpdG9yX2lkIjoiNzU0NTA4MDE2MTQ1NTk0NDA5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fa1068a72f5c46f667ef44d0b8a61cfab42783b7065b52405d8831df6f45373a |
| hovercard-subject-tag | issue:756491255 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-openxml/python-docx/902/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2788a4ffff3b1d39892d584a572950d3b6e1aef18e7bce5f704dd634d9c238a9/python-openxml/python-docx/issues/902 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2788a4ffff3b1d39892d584a572950d3b6e1aef18e7bce5f704dd634d9c238a9/python-openxml/python-docx/issues/902 |
| og:image:alt | The document below contains a picture with a hyperlink to an internal bookmark. PictureBookmarks.docx (The very last picture links to the very first Heading1) I get this error message when reading ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aorsten |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4922b452d03cd8dbce479d866a11bc25b59ef6ee2da23aa9b0ddefa6bd4d0064 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-openxml/python-docx git https://github.com/python-openxml/python-docx.git |
| octolytics-dimension-user_id | 3403760 |
| octolytics-dimension-user_login | python-openxml |
| octolytics-dimension-repository_id | 13592924 |
| octolytics-dimension-repository_nwo | python-openxml/python-docx |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 13592924 |
| octolytics-dimension-repository_network_root_nwo | python-openxml/python-docx |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7e5ae23c70136152637ceee8d6faceb35596ec46 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width