Skip to content

AttributeError: 'NoneType' object has no attribute 'strip' #19

Open

Description

@bariskurt

I just get the following error message:

Traceback (most recent call last):
File "/usr/local/bin/pdf-diff", line 11, in
load_entry_point('pdf-diff==0.9.0', 'console_scripts', 'pdf-diff')()
File "/usr/local/lib/python3.5/dist-packages/pdf_diff-0.9.0-py3.5.egg/pdf_diff/command_line.py", line 491, in main
changes = compute_changes(args.files[0], args.files[1], top_margin=float(args.top_margin), bottom_margin=float(args.bottom_margin))
File "/usr/local/lib/python3.5/dist-packages/pdf_diff-0.9.0-py3.5.egg/pdf_diff/command_line.py", line 14, in compute_changes
docs = [serialize_pdf(0, pdf_fn_1, top_margin, bottom_margin), serialize_pdf(1, pdf_fn_2, top_margin, bottom_margin)]
File "/usr/local/lib/python3.5/dist-packages/pdf_diff-0.9.0-py3.5.egg/pdf_diff/command_line.py", line 30, in serialize_pdf
normalized_text = run["text"].strip()
AttributeError: 'NoneType' object has no attribute 'strip'

Activity

  1. tkkiran commented on Jan 2, 2018

    @tkkiran

    Have the same issue. When running in python3.5 inside a virtual environment.

  2. wfranus commented on Feb 20, 2018

    @wfranus
    Contributor

    I had the same error. In fact, run["text"] is equal to None when an element being parsed is not a word, but an image or a symbol (rendered latex \square symbol in my case).

    Here is my solution:

    def serialize_pdf(i, fn, top_margin, bottom_margin):
        box_generator = pdf_to_bboxes(i, fn, top_margin, bottom_margin)
        box_generator = mark_eol_hyphens(box_generator)
    
        boxes = []
        text = []
        textlength = 0
        for run in box_generator:
            if run["text"] is None:        # <--- I added these two lines
                continue                   #
    
            normalized_text = run["text"].strip()

    Since the script compares only the text in PDF, I just skipped to the next iteration when run["text"] = None.

  3. JoshData commented on Feb 21, 2018

    @JoshData
    Owner

    If you submit a pull request, I'd be glad to merge that fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions