emmett-framework / emmett

The web framework for inventors
BSD 3-Clause "New" or "Revised" License
1.09k stars 72 forks source link

Error with response.wrap_dbfile(db, filename) [emmett 2.6] #515

Closed josejachuf closed 1 month ago

josejachuf commented 1 month ago

replacing this

from emmett.helpers import stream_dbfile 

@app.route("/download/<str:filename>")
async def download(filename):
    stream_dbfile(db, filename)

With this


from emmett import response

@app.route("/download/<str:filename>")
async def download(filename):
    return response.wrap_dbfile(db, filename)

failure:

[ERROR] Application callable raised an exception Traceback (most recent call last): File "/venv/lib/python3.11/site-packages/granian/_futures.py", line 4, in future_watcher await inner(watcher.scope, watcher.proto) File "/venv/lib/python3.11/site-packages/granian/rsgi.py", line 81, in _http_logger rv = await callback(scope, proto) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.11/site-packages/emmett_core/protocols/rsgi/handlers.py", line 63, in call if coro := http.rsgi(protocol): ^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.11/site-packages/emmett_core/http/response.py", line 91, in rsgi protocol.response_str(self.status_code, list(self.rsgi_headers), self.body) File "/venv/lib/python3.11/site-packages/granian/rsgi.py", line 62, in response_str return self.inner.response_str(status, headers, body) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: argument 'body': 'HTTPFileResponse' object cannot be converted to 'PyString'

The stream_dbfile version still works on version 2.6.x

gi0baro commented 1 month ago

This is fixed in 2.6.1 Thank you for reporting this

josejachuf commented 1 month ago

Hi @gi0baro, Something broke with this update

TimeoutError in /usr/lib/python3.11/asyncio/tasks.py TimeoutError

        # exception, we should re-raise it
        # See https://bugs.python.org/issue40607
        try:
            return fut.result()
        except exceptions.CancelledError as exc:
            raise exceptions.TimeoutError() from exc
finally:
    timeout_handle.cancel()

Detail:

ERROR in handlers [/venv/lib/python3.11/site-packages/emmett_core/protocols/rsgi/handlers.py:145]: Application exception: Traceback (most recent call last): File "/usr/lib/python3.11/asyncio/tasks.py", line 500, in wait_for return fut.result() ^^^^^^^^^^^^ File "/venv/lib/python3.11/site-packages/emmett/orm/connection.py", line 259, in _acquire_loop conn, _opened = await self._connection_open_loop() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.11/site-packages/emmett/orm/connection.py", line 159, in _connection_open_loop return (await self._loop.run_in_executor(None, self._connector_loop), True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/venv/lib/python3.11/site-packages/emmett_core/protocols/rsgi/handlers.py", line 135, in dynamic_handle r http = await self.router.dispatch(request, response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.11/site-packages/emmett_core/routing/router.py", line 230, in dispatch return await match.dispatch(reqargs, response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.11/site-packages/emmett_core/routing/dispatchers.py", line 57, in dispatch await self._parallel_flow(self.flow_open) File "/venv/lib/python3.11/site-packages/emmett_core/routing/dispatchers.py", line 17, in _parallel_flow raise task.exception() File "/venv/lib/python3.11/site-packages/emmett/orm/base.py", line 40, in open await self.db.connection_open_loop() File "/venv/lib/python3.11/site-packages/emmett/orm/connection.py", line 330, in _connect_loop self.connection, _opened = await self._connection_manager.connect_loop() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.11/site-packages/emmett/orm/connection.py", line 227, in connect_loop return await asyncio.wait_for(self._acquire_loop(), self.connect_timeout or None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/tasks.py", line 502, in wait_for raise exceptions.TimeoutError() from exc TimeoutError

gi0baro commented 1 month ago

@josejachuf which database engine are you using?

josejachuf commented 1 month ago

My error, apologies. The VPN was dropped