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

Add support for wsgi.file_wrapper #40

Closed
dalf opened this issue Jan 17, 2023 · 2 comments
Closed

Add support for wsgi.file_wrapper #40

dalf opened this issue Jan 17, 2023 · 2 comments
Labels
enhancement New feature or request wsgi Issue related to WSGI protocol

Comments

@dalf
Copy link

dalf commented Jan 17, 2023

I've tried to run https://github.com/benbusby/whoogle-search a WSGI application using granian --interface wsgi app.

The logs show that wsgi.file_wrapper is not supported:

[ERROR] Exception on /static/build/main.68be5054.css [GET]
Traceback (most recent call last):
  File "/home/alexandre/code/whoogle-search/venv/lib/python3.9/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/alexandre/code/whoogle-search/venv/lib/python3.9/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/alexandre/code/whoogle-search/venv/lib/python3.9/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/alexandre/code/whoogle-search/venv/lib/python3.9/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/alexandre/code/whoogle-search/venv/lib/python3.9/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/alexandre/code/whoogle-search/venv/lib/python3.9/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/alexandre/code/whoogle-search/venv/lib/python3.9/site-packages/flask/helpers.py", line 1081, in send_static_file
    return send_from_directory(
  File "/home/alexandre/code/whoogle-search/venv/lib/python3.9/site-packages/flask/helpers.py", line 771, in send_from_directory
    return send_file(filename, **options)
  File "/home/alexandre/code/whoogle-search/venv/lib/python3.9/site-packages/flask/helpers.py", line 640, in send_file
    data = wrap_file(request.environ, file)
  File "/home/alexandre/code/whoogle-search/venv/lib/python3.9/site-packages/werkzeug/wsgi.py", line 529, in wrap_file
    return environ.get("wsgi.file_wrapper", FileWrapper)(file, buffer_size)
TypeError: 'NoneType' object is not callable

For reference: https://peps.python.org/pep-3333/#optional-platform-specific-file-handling

@gi0baro
Copy link
Member

gi0baro commented Jan 17, 2023

@dalf so, aside from supporting this, since is optional, this is actually a bug, as Granian should not populate the wsgi.file_wrapper key of environ.

I gonna leave this opened for the support request, while the bug is now tracked in #41. Once closed, the app you tried should work without the file wrapper support.

@gi0baro gi0baro added enhancement New feature or request wsgi Issue related to WSGI protocol labels Jan 19, 2023
@gi0baro
Copy link
Member

gi0baro commented Jan 22, 2024

I'm closing this as wsgi.file_wrapper is implemented around file descriptors, so it won't be beneficial in the same way of ASGI zerocopysend in #93

@gi0baro gi0baro closed this as completed Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wsgi Issue related to WSGI protocol
Projects
None yet
Development

No branches or pull requests

2 participants