From ca7f893729ab56e86d78542f7a9d858d17bd3f72 Mon Sep 17 00:00:00 2001 From: YoungjuKim Date: Sat, 17 Oct 2026 03:53:18 +0900 Subject: [PATCH] Fix the In-Depth Example in the docs to return bytes Both "In-Depth Example" snippets returned str from a WSGI app, which wsgiref rejects with "write() argument must be a bytes instance", so they answered 500 instead of the output shown on the page. Return bytes and start the final example with the "Hashes:" line that the sample output already shows. Signed-off-by: YoungjuKim --- docs/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/index.md b/docs/index.md index a11f65e..6188aa9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -84,7 +84,7 @@ import python_multipart def simple_app(environ, start_response): start_response('200 OK', [('Content-type', 'text/plain')]) - return ['Hashes:\n'] + return [b'Hashes:\n'] from wsgiref.simple_server import make_server httpd = make_server('', 8123, simple_app) @@ -117,7 +117,7 @@ import python_multipart from python_multipart.multipart import parse_options_header def simple_app(environ, start_response): - ret = [] + ret = [b'Hashes:\n'] # Python 2 doesn't have the "nonlocal" keyword from Python 3, so we get # around it by setting attributes on a dummy object. @@ -135,7 +135,7 @@ def simple_app(environ, start_response): # Our current part is done, so we can finish the hash. def on_part_end(): - ret.append("Part hash: %s" % (g.hash.hexdigest(),)) + ret.append(b"Part hash: %s\n" % (g.hash.hexdigest().encode(),)) # Parse the Content-Type header to get the multipart boundary. content_type, params = parse_options_header(environ['CONTENT_TYPE'])