Uvicorn inserted HTTP headers into CSV responses with the sanic framework
See original GitHub issueChecklist
- The bug is reproducible against the latest release and/or
master
. - There are no similar issues or pull requests to fix it yet.
Describe the bug
I am running uvicorn for an app written with the sanic framework. If i run the app directly to download a CSV file, the file gets returned normally. But when I run it with uvicorn, it has inserted HTTP header information.
To reproduce
app.py (this example is straight from the sanic docs: https://sanic.readthedocs.io/en/latest/sanic/streaming.html#response-streaming)
from sanic import Sanic
from sanic.response import stream
app = Sanic(__name__)
@app.route("/")
async def test(request):
async def sample_streaming_fn(response):
await response.write('foo,')
await response.write('bar')
return stream(sample_streaming_fn, content_type='text/csv')
Expected behavior
Running sanic directly as a module should give the same result as running the app with uvicorn.
python -m sanic app.app
$ curl http://127.0.0.1:8000
foo,bar
Actual behavior
Using uvicorn to run the app:
uvicorn app:app
$ curl http://127.0.0.1:8000
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: text/csv
Connection: close
4
foo,
3
bar
0
Debugging material
Environment
- Running uvicorn 0.11.8 with CPython 3.8.1 on Darwin
uvicorn app:app
Additional context
I am using 0.11.8 here but I can reproduce with 0.12.2 also.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
HTTP headers get inserted at the start of a CSV download on ...
I have rows of dicts and want to make it available for download as a CSV file. ... Uvicorn inserted HTTP headers into...
Read more >Sanic Documentation
Sanic is a Python 3.6+ web server and web framework that's written to go fast. It allows the usage of the async/await syntax...
Read more >Headers | Sanic Framework
Request and response headers are available in the Request and HTTPResponse objects, respectively. They make use of the multidict package (opens new window)...
Read more >WebFrameworks - Python Wiki
A Web framework is a collection of packages or modules which allow developers to write Web applications (see WebApplications) or services ...
Read more >Simon Willison - Datasette documentation
Insert data into a SQLite database from JSON, CSV or TSV, automatically creating tables with the correct schema or altering existing tables ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Tanks @ahopkins !
This issue can be closed.