excalibur
excalibur copied to clipboard
TypeError: object of type 'NoneType' has no len()
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!
Having the same issue. Any fix?
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'?
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
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
@bulatovv I tried your branch with the pull request, and still get the same error. I can't seem to actually upload anything without getting the "500 Internal Server Error". However, I don't get anything in my terminal after
TypeError: object of type 'NoneType' has no len() 127.0.0.1 - - [11/Apr/2025 13:50:43] "GET /workspaces/56d9ced0-46dd-4d10-b959-c22cb26e6d29 HTTP/1.1" 500 -
You seem to have some more details, is there a debug/verbose mode I could activate to get more descriptive errors?
There's still a logic bug here.
if imagepaths is not none or imagepaths|length == 0 makes no sense, because if imagepaths is none, it still evaluates the length check.
I suspect it should be if imagepaths is not none and imagepaths|length == 0.
@bulatovv I tried your branch with the pull request, and still get the same error. I can't seem to actually upload anything without getting the "500 Internal Server Error". However, I don't get anything in my terminal after
TypeError: object of type 'NoneType' has no len() 127.0.0.1 - - [11/Apr/2025 13:50:43] "GET /workspaces/56d9ced0-46dd-4d10-b959-c22cb26e6d29 HTTP/1.1" 500 -You seem to have some more details, is there a debug/verbose mode I could activate to get more descriptive errors?
Which pull request did you try?
`TypeError: object of type 'NoneType' has no len() 127.0.0.1 - - [11/Apr/2025 13:50:43] "GET /workspaces/56d9ced0-46dd-4d10-b959-c22cb26e6d29 HTTP/1.1" 500 -
Which pull request did you try?
I am seeing this with excalibur-py/1.0.1 from pip and manually changing isEncrypted in task.py. So basically #194. Error is in excalibur/www/templates/workspace.html:12, so https://github.com/camelot-dev/excalibur/issues/193#issuecomment-2829342486. Changing to "and" causes the UI to no longer crash, but it loads "http://localhost:5000/workspaces/{UUID}", displaying "Processing" and reloading the URL over and over again without any progress (with just 0.5s delay from workspace.html:162, so possibly overloading the system).
Using current git master works as expected.
having the same problem
After applying #194, #195 and #199 to master, I'm seeing the same — "displaying "Processing" and reloading the URL over and over again without any progress".