Flask responses need to be bytestrings, not real strings
authorMagnus Hagander <magnus@hagander.net>
Fri, 28 Jun 2019 17:02:56 +0000 (19:02 +0200)
committerMagnus Hagander <magnus@hagander.net>
Fri, 28 Jun 2019 17:02:56 +0000 (19:02 +0200)
Seems if a string is returned, flask just turns it into an empty
response (rather than converting it to utf8 as expected). These are
trivial hardcoded strings though, so just use bytestrings.

redirector/redirector.py

index 4f8fa9dcd0b8b61ba489065987f27c7684400c07..6cce162bbc4e3ba009d167fff9a966fe58a04cc5 100755 (executable)
@@ -53,7 +53,7 @@ def application(environ, start_response):
                        start_response('404 Not Found', [
                                        ('Content-type', 'text/plain'),
                                        ])
-                       return ["Link not found\n"]
+                       return [b"Link not found\n"]
 
                # We have a link, return a redirect to it
                start_response('301 Moved Permanently', [
@@ -62,9 +62,9 @@ def application(environ, start_response):
                                ('X-Planet', str(id))
                                ])
                return [
-                       "<html>\n<head>\n<title>postgr.es</title>\n</head>\n<body>\n",
-                       "<a href=\"%s\">moved here</a>\n" % r[0][0],
-                       "</body>\n</html>\n"
+                       b"<html>\n<head>\n<title>postgr.es</title>\n</head>\n<body>\n",
+                       b"<a href=\"%s\">moved here</a>\n" % r[0][0],
+                       b"</body>\n</html>\n"
                        ]
        except Exception as ex:
                start_response('500 Internal Server Error', [