In order to open password-protected documents, you have to pass your password to LoadOptions class constructor or assign it to its Password property of an instance of LoadOptions class:
fromgroupdocs.redactionimportRedactorfromgroupdocs.redaction.optionsimportSaveOptions,LoadOptionsfromgroupdocs.redaction.redactionsimportExactPhraseRedaction,ReplacementOptionsdefload_password_protected_file():# Specify the load options with the document passwordload_opt=LoadOptions("mypassword")# Specify the redaction optionsrepl_opt=ReplacementOptions("[personal]")ex_red=ExactPhraseRedaction("John Doe",repl_opt)# Load the password-protected document to be redactedwithRedactor("./protected.docx",load_opt)asredactor:# Apply the redactionredactor.apply(ex_red)# Save the redacted document in its original formatso=SaveOptions()so.add_suffix=Trueso.rasterize_to_pdf=Falseso.redacted_file_suffix="redacted"result_path=redactor.save(so)print(f"Document redacted successfully.\nCheck output in {result_path}.")if__name__=="__main__":load_password_protected_file()
protected.docx is the sample file used in this example. Click here to download it.