Catch pyPDF2 key error

This commit is contained in:
Finn Stutzenstein 2021-02-15 07:22:38 +01:00
parent c1b4d3154d
commit e9c2dc90d5
No known key found for this signature in database
GPG Key ID: 9042F605C6324654

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