Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle "encrpyted" PDFs #1

Open
SteveClement opened this issue Sep 13, 2018 · 0 comments
Open

Handle "encrpyted" PDFs #1

SteveClement opened this issue Sep 13, 2018 · 0 comments

Comments

@SteveClement
Copy link
Owner

Unlock protected PDF in Python

PDF Miner Encryption Error

consider:

from subprocess import call
call('qpdf --password=%s --decrypt %s %s' %('', pdf_filename, pdf_filename_decr), shell=True)

Error message

./report_to_misp.py -r isr2014.pdf
Parsing report(s) at isr2014.pdf...
Traceback (most recent call last):
  File "/home/steve/.virtualenvs/report_to_misp/local/lib/python3.6/site-packages/iocp/Parser.py", line 293, in parse
    self.parser_func(f, path)
  File "/home/steve/.virtualenvs/report_to_misp/local/lib/python3.6/site-packages/iocp/Parser.py", line 241, in parse_pdf
    self.parser_func(f, fpath)
  File "/home/steve/.virtualenvs/report_to_misp/local/lib/python3.6/site-packages/iocp/Parser.py", line 218, in parse_pdf_pdfminer
    for page in PDFPage.get_pages(f, pagenos, check_extractable=True):
  File "/home/steve/.virtualenvs/report_to_misp/local/lib/python3.6/site-packages/pdfminer/pdfpage.py", line 132, in get_pages
    raise PDFTextExtractionNotAllowed('Text extraction is not allowed: %r' % fp)
pdfminer.pdfdocument.PDFTextExtractionNotAllowed: Text extraction is not allowed: <_io.BufferedReader name='isr2014.pdf'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "ioc_parser/bin/iocp", line 53, in <module>
    parser.parse(args.PATH)
  File "/home/steve/.virtualenvs/report_to_misp/local/lib/python3.6/site-packages/iocp/Parser.py", line 308, in parse
    self.handler.print_error(path, e)
  File "/home/steve/.virtualenvs/report_to_misp/local/lib/python3.6/site-packages/iocp/Output.py", line 74, in print_error
    print((json.dumps(data)))
  File "/usr/lib/python3.6/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'PDFTextExtractionNotAllowed' is not JSON serializable
SteveClement pushed a commit that referenced this issue Sep 13, 2018
Fixing remaining python2 print statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant