Currently I am using the PyPDF 2 as a dependency.
I have encountered some encrypted files and handled them as you normally would (in the following code):
<
You can try PyMuPDF package, it can open encrypted files and solved my problems.
PyMuPDF
Reference: PyMuPDF Documentation