Skip to content

function based wsgi container and return value bytes expected #2710

Open
@emattiza

Description

@emattiza

In going through the docs, i saw a snippet to test a wsgi container, and ran as-is in a fresh environment. What i encountered was an error related to the docs such that the return value did not encode to bytes to send as the output of the WSGI container rudimentary function. Specifically, in https://www.tornadoweb.org/en/stable/wsgi.html

import tornado
import tornado.wsgi
import tornado.httpserver
import tornado.ioloop

def simple_app(environ, start_response):
    status = "200 OK"
    response_headers = [("Content-type", "text/plain")]
    start_response(status, response_headers)
    return ["Hello world!\n"]

container = tornado.wsgi.WSGIContainer(simple_app)
http_server = tornado.httpserver.HTTPServer(container)
http_server.listen(8888)
tornado.ioloop.IOLoop.current().start()

The fix i applied was to change

return ["Hello world!\n"]

into

return ["Hello world!\n".encode("utf-8")]

Would a docs update suffice to contain this? Worth putting in a doc test? I would be a first time contributor here for the PR if so.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions