question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uvicorn inserted HTTP headers into CSV responses with the sanic framework

See original GitHub issue

Checklist

  • 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:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
euri10commented, Oct 25, 2020

Tanks @ahopkins !

1reaction
ahopkinscommented, Oct 25, 2020

This issue can be closed.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found