Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accommodate NULL relationship (by skipping) #678

Open
LightningSpace opened this issue May 29, 2019 · 14 comments
Open

fix: accommodate NULL relationship (by skipping) #678

LightningSpace opened this issue May 29, 2019 · 14 comments

Comments

@LightningSpace
Copy link

when i using "docx.Document("a.docx")" want to open that document, had make 'keyError',what is happend?
image
the file i unzip, idont know what is that?Does this file make the keyError?
image

@LightningSpace LightningSpace changed the title I can open .docx using python-docx ,"There is no item named 'NULL' in the archive" I cannot open .docx using python-docx ,"There is no item named 'NULL' in the archive" May 29, 2019
@LightningSpace
Copy link
Author

ps: the word file was created or saved by MSWORD2016,however,rels always has relationship target is null.

@scanny
Copy link
Contributor

scanny commented May 29, 2019

We've seen this problem before, I think it comes from a Word Add-in like a "management-pack" or something that improperly leaves dangling relationships. There is some more information about it here: scanny/python-pptx#206 where it came up in the sister project python-pptx. It looks like if you delete that relationship from the .rels XML file it solves the problem. Otherwise you can patch the loading code.

@scanny scanny changed the title I cannot open .docx using python-docx ,"There is no item named 'NULL' in the archive" fix: accommodate NULL relationship (by skipping) May 29, 2019
@LightningSpace
Copy link
Author

when i skipping ,another problem arises,the relationship have in the rels
image

@LightningSpace
Copy link
Author

RootGcc.docx

that's my document , i try to find where the error position

@scanny
Copy link
Contributor

scanny commented May 30, 2019

Looks like you corrupted the main rels file somehow.

@LightningSpace
Copy link
Author

I have solved this problem by deleting the NULL relationship each time, and then packaged it into docx. thank you very much

@whybeyoung
Copy link

The same problem i have . So how to avoid this in code

@deiferni
Copy link

deiferni commented Oct 30, 2019

Just to bump this issue a bit, we have also encountered the problem mentioned here in production. I have manually fixed the affected word-document but of course it would be more elegant if python-docx could handle such incorrect relationships gracefully 😉.

@zhangjx53
Copy link

It seems that python-docx can't handle such problem. Can anyone tell me how to avoid this in code ,or how to delete the null relationship in word 2016? thanks a lot~

@ngc7023
Copy link

ngc7023 commented Jul 20, 2021

I fix this problem by the following steps:

  1. Modify the file extension from .docx to .zip
  2. Unzip this file
  3. Find the rel file and delete the with 'NULL'
  4. Zip the file and modify the file extension to .docx

@scanny
Copy link
Contributor

scanny commented Jul 20, 2021

@ngc7023 how do you "delete the with 'NULL'"? Do you just do that by hand or do you have some code you use?

@ngc7023
Copy link

ngc7023 commented Jul 21, 2021

@scanny
I just do that by hand.
The step 3 should be modified as 'Open the rel file(.xml) and delete tag of relationship with 'NULL' by hand'.
I cannot promise the docx file will be totally repaired, because some codes are deleted. At least the keyError will not be raised.

@yingang
Copy link

yingang commented Jan 11, 2022

bad_file.docx

Just encountered the same situation (as attached), just wondering if this kind of bad file would be handled gracefully by python-docx? Or prefer not to fix it?

@wonzer
Copy link

wonzer commented Nov 1, 2022

@yingang @scanny @deiferni @whybeyoung @zhangjx53 You can find a solution here->
#1105 (comment)

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

No branches or pull requests

8 participants