[Twisted-web] requestHeaders issues

Jean-Paul Calderone exarkun at divmod.com
Thu Jun 5 16:01:15 EDT 2008


On Thu, 5 Jun 2008 14:58:21 -0400, Phil Christensen <phil at bubblehouse.org> wrote:
>Hi all,
>
>I've run into a problem in Twisted.Web with a recent addition to SVN  head. 
>The problem occurs in my WSGI gateway module, which is derived  from web2's 
>version. When I'm creating the environment dictionary by  iterating like 
>this:
>
>     # Propagate HTTP headers
>     for title in request.received_headers:
>         header = request.received_headers[title]
>         ...
>         ...

Hi Phil,

Thanks for reporting this and tracking down the cause.  I'll back out that
revision shortly until it can be fixed.

>
>If I make those changes and use `requestHeaders` instead, like this:
>
>     # Propagate HTTP headers
>     for title in request.received_headers:
>         header = request.received_headers[title]
>         ...
>         ...
>
>I instead get the following traceback:
>
>     Traceback (most recent call last):
>       File "/Users/phil/Workspace/modu/modu/web/wsgi.py", line 91, in 
>createCGIEnvironment
>         for title in request.requestHeaders:
>     exceptions.TypeError: 'Headers' object is not iterable
>
>which seems strange to me, since from what I can tell, 
>request.requestHeaders should be a http_headers._DictHeaders instance. 
>Should I be calling request.requestHeaders.getAllRawHeaders() and  iterate 
>through that result instead?
>
>Any guidance in this matter would be greatly appreciated.

In the future, using `requestHeaders.getAllRawHeaders´ will be the right
thing to do.  `request.requestHeaders´ isn't a `_DictHeaders´ though, it's
a `Headers´ - `request.received_headers´ is the `_DictHeaders´.  I suspect
that's what you meant, though.

Jean-Paul



More information about the Twisted-web mailing list