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

TypeError: object of type 'NoneType' has no len() #193

Open
mplewis opened this issue Jan 8, 2025 · 4 comments
Open

TypeError: object of type 'NoneType' has no len() #193

mplewis opened this issue Jan 8, 2025 · 4 comments

Comments

@mplewis
Copy link

mplewis commented Jan 8, 2025

Hello! I'm having trouble using Excalibur out of the box.

What I did

Installed Excalibur and set it up:

pip install excalibur-py
excalibur initdb
excalibur webserver

Then, uploaded a PDF via the web interface.

Expected behavior

Excalibur extracts data from my PDF for me.

Actual behavior

I receive a 500 Internal Server Error at http://localhost:5000/workspaces/c644cced-85fe-42a7-92c9-aa6dcc6fc72a:

excalibur webserver
 * Serving Flask app 'excalibur.www.app'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
127.0.0.1 - - [08/Jan/2025 11:40:05] "GET / HTTP/1.1" 302 -
127.0.0.1 - - [08/Jan/2025 11:40:05] "GET /files HTTP/1.1" 200 -
127.0.0.1 - - [08/Jan/2025 11:40:05] "GET /static/css/vendor/bootstrap.min.css HTTP/1.1" 200 -
127.0.0.1 - - [08/Jan/2025 11:40:05] "GET /static/js/vendor/jquery-3.3.1.min.js HTTP/1.1" 200 -
127.0.0.1 - - [08/Jan/2025 11:40:05] "GET /static/css/base.css HTTP/1.1" 200 -
127.0.0.1 - - [08/Jan/2025 11:40:05] "GET /static/js/vendor/popper.min.js HTTP/1.1" 200 -
127.0.0.1 - - [08/Jan/2025 11:40:05] "GET /static/js/vendor/bootstrap.min.js HTTP/1.1" 200 -
127.0.0.1 - - [08/Jan/2025 11:40:05] "GET /static/js/files.js HTTP/1.1" 200 -
127.0.0.1 - - [08/Jan/2025 11:40:05] "GET /static/favicon.ico HTTP/1.1" 200 -
127.0.0.1 - - [08/Jan/2025 11:40:12] "POST /files HTTP/1.1" 200 -
[2025-01-08 11:40:12,401] ERROR in app: Exception on /workspaces/c644cced-85fe-42a7-92c9-aa6dcc6fc72a [GET]
Traceback (most recent call last):
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/flask/app.py", line 919, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/excalibur/www/views.py", line 106, in workspaces
    return render_template(
           ^^^^^^^^^^^^^^^^
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/flask/templating.py", line 150, in render_template
    return _render(app, template, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/flask/templating.py", line 131, in _render
    rv = template.render(context)
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/jinja2/environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/excalibur/www/templates/workspace.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/excalibur/www/templates/base.html", line 61, in top-level template code
    {% block workspace %}{% endblock %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mplewis/.local/share/mise/installs/python/3.12.7/lib/python3.12/site-packages/excalibur/www/templates/workspace.html", line 12, in block 'workspace'
    {% if imagepaths is not none or imagepaths|length == 0 %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object of type 'NoneType' has no len()
127.0.0.1 - - [08/Jan/2025 11:40:12] "GET /workspaces/c644cced-85fe-42a7-92c9-aa6dcc6fc72a HTTP/1.1" 500 -

Versions

>>> import platform; print(platform.platform())
macOS-15.2-arm64-arm-64bit
>>> import sys; print('Python', sys.version)
Python 3.12.7 (main, Oct  2 2024, 15:45:55) [Clang 18.1.8 ]
>>> import numpy; print('NumPy', numpy.__version__)
NumPy 2.2.1
>>> import cv2; print('OpenCV', cv2.__version__)
OpenCV 4.10.0
>>> import excalibur; print('Excalibur', excalibur.__version__)
Excalibur 1.0.1

Let me know if I can provide any more info to help you replicate this issue. Thanks!

@divan
Copy link

divan commented Jan 14, 2025

Having the same issue. Any fix?

@bulatovv
Copy link

I think this error is due to the pypdf version being updated in the recent Camelot release, and the pypdf API was changed between the old and new versions. Some code still uses the old API: https://github.com/camelot-dev/excalibur/blame/6bc1e13c705b7db1ff0031758e684dafcc283953/excalibur/utils/task.py#L38

I think if we change infile.isEntrypted to infile.is_encrypted, the issue will be fixed.

Also, I think some unit tests should be added to the CI to prevent such issues.

[2025-01-14 06:51:17,032] ERROR in app: Exception on /workspaces/06b49eae-80a4-45db-b182-dabab42081e8 [GET]
Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 919, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/excalibur/www/views.py", line 106, in workspaces
    return render_template(
           ^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/flask/templating.py", line 150, in render_template
    return _render(app, template, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/flask/templating.py", line 131, in _render
    rv = template.render(context)
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
  File "/app/.venv/lib/python3.12/site-packages/jinja2/environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/app/.venv/lib/python3.12/site-packages/excalibur/www/templates/workspace.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "/app/.venv/lib/python3.12/site-packages/excalibur/www/templates/base.html", line 61, in top-level template code
    {% block workspace %}{% endblock %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/excalibur/www/templates/workspace.html", line 12, in block 'workspace'
    {% if imagepaths is not none or imagepaths|length == 0 %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object of type 'NoneType' has no len()
172.17.0.1 - - [14/Jan/2025 06:51:17] "GET /workspaces/06b49eae-80a4-45db-b182-dabab42081e8 HTTP/1.1" 500 -
ERROR:root:'PdfReader' object has no attribute 'isEncrypted'
Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/excalibur/tasks.py", line 25, in split
    extract_pages, total_pages = get_pages(file.filepath, file.pages)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/excalibur/utils/task.py", line 38, in get_pages
    if infile.isEncrypted:
       ^^^^^^^^^^^^^^^^^^
AttributeError: 'PdfReader' object has no attribute 'isEncrypted'. Did you mean: 'is_encrypted'?

@bulatovv
Copy link

bulatovv commented Jan 14, 2025

I fixed the property name, but I still get the error with the template. However, the file processing issue is resolved. The error stops appearing once the file is fully processed, and you can access the workspaces/{uuid} route without any problem after
that.
Pull request is #194

@bulatovv
Copy link

bulatovv commented Jan 14, 2025

Downloading the extracted data is also broken.

[2025-01-14 07:40:10,507] ERROR in app: Exception on /download [POST]
Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 919, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return
]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/excalibur/www/views.py", line 262, in download
    return send_from_directory(
           ^^^^^^^^^^^^^^^^^^^^
TypeError: send_from_directory() missing 1 required positional argument: 'path'

Fix is here: #195

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

3 participants