From: Brian Warner Date: Wed, 21 Jan 2015 18:31:31 +0000 (-0800) Subject: Appease req.setHeader by passing bytes, not ints. X-Git-Tag: allmydata-tahoe-1.10.1a1~81^2 X-Git-Url: https://git.rkrishnan.org/reliability?a=commitdiff_plain;h=refs%2Fpull%2F137%2Fhead;p=tahoe-lafs%2Ftahoe-lafs.git Appease req.setHeader by passing bytes, not ints. twisted.web.http.Request.setHeader() really wants a "bytes" object, but we've been passing integers like len(body). Twisted-12.3 started to complain about this (with a DeprecationWarning), but the warning is usually silenced because py2.7 disables deprecations by default. This fixes Tahoe's misbehavior, but others remain (in Nevow, at least). I plan to set up some tooling to run tests with PYTHONWARNINGS=default::DeprecationWarning and collect others. We won't be able to fix the ones that occur outside of Tahoe, but at least we should be able to fix our own. refs ticket:2312 --- diff --git a/src/allmydata/web/common.py b/src/allmydata/web/common.py index af5f6d26..52fed6a0 100644 --- a/src/allmydata/web/common.py +++ b/src/allmydata/web/common.py @@ -206,7 +206,7 @@ def plural(sequence_or_length): def text_plain(text, ctx): req = IRequest(ctx) req.setHeader("content-type", "text/plain") - req.setHeader("content-length", len(text)) + req.setHeader("content-length", b"%d" % len(text)) return text class WebError(Exception): @@ -315,7 +315,7 @@ class MyExceptionHandler(appserver.DefaultExceptionHandler): req.setHeader("content-type", "text/plain;charset=utf-8") if isinstance(text, unicode): text = text.encode("utf-8") - req.setHeader("content-length", str(len(text))) + req.setHeader("content-length", b"%d" % len(text)) req.write(text) # TODO: consider putting the requested URL here req.finishRequest(False) diff --git a/src/allmydata/web/filenode.py b/src/allmydata/web/filenode.py index ff65acc9..7d61447a 100644 --- a/src/allmydata/web/filenode.py +++ b/src/allmydata/web/filenode.py @@ -452,7 +452,7 @@ class FileDownloader(rend.Page): contentsize = last - first + 1 size = contentsize - req.setHeader("content-length", str(contentsize)) + req.setHeader("content-length", b"%d" % contentsize) if req.method == "HEAD": return ""