Uwsgi: Warn if (Py3) WSGI app returns Unicode strings instead of bytes

Created on 4 Mar 2014  路  4Comments  路  Source: unbit/uwsgi

Though I'm largely ignorant of the problem space outside the most naive and simplest case, but I think it'd be great to warn the user if the WSGI application returns a Python3 string instead an iterable of bytes.

easy patch skills-c

Most helpful comment

I've been banging my head several hours on this. String output is silently swallowed with Python 3 if I do this:

def app(environ, start_response):
    start_response('200 OK', [])
    return ["foo bar"]

Whereas it correctly processes the response if I use bytes:

def app(environ, start_response):
    start_response('200 OK', [])
    return [b"foo bar"]

Just for a missing b sign my program becomes a nightmare to troubleshoot! Please issue a warning.

All 4 comments

it is a complex topic as lot of middlewares/modules work by returning empty strings (just as a trick). They works perfectly now (even if they are wrong). Maybe we could send a warning only for the first "unicode" response

Or maybe only warn if the response is a non-empy Unicode string.

it seems a good idea

I've been banging my head several hours on this. String output is silently swallowed with Python 3 if I do this:

def app(environ, start_response):
    start_response('200 OK', [])
    return ["foo bar"]

Whereas it correctly processes the response if I use bytes:

def app(environ, start_response):
    start_response('200 OK', [])
    return [b"foo bar"]

Just for a missing b sign my program becomes a nightmare to troubleshoot! Please issue a warning.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alanhamlett picture alanhamlett  路  6Comments

vlcinsky picture vlcinsky  路  3Comments

ngnpope picture ngnpope  路  5Comments

pdonadeo picture pdonadeo  路  5Comments

cancan101 picture cancan101  路  4Comments