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

View File

@ -20,8 +20,9 @@ def get_pdf_information(mediafile):
try: try:
pdf = PdfFileReader(mediafile) pdf = PdfFileReader(mediafile)
result["pages"] = pdf.getNumPages() result["pages"] = pdf.getNumPages()
except PdfReadError: except (PdfReadError, KeyError):
# File could be encrypted but not be detected by PyPDF. # 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["pages"] = 0
result["encrypted"] = True result["encrypted"] = True
return result return result