Merge pull request #5892 from FinnStutzenstein/PdfKeyError

Catch pyPDF2 key error
This commit is contained in:
Finn Stutzenstein 2021-02-15 07:37:10 +01:00 committed by GitHub
commit 05ec54927b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -20,8 +20,9 @@ def get_pdf_information(mediafile):
try:
pdf = PdfFileReader(mediafile)
result["pages"] = pdf.getNumPages()
except PdfReadError:
except (PdfReadError, KeyError):
# File could be encrypted but not be detected by PyPDF.
# KeyError: https://github.com/mstamy2/PyPDF2/issues/353 Very rare to occur, but do not raise a 500
result["pages"] = 0
result["encrypted"] = True
return result