[Twisted-web] web2: handling data from an http PUT request?

David Reid dreid at dreid.org
Fri Aug 11 15:46:02 CDT 2006

On Fri, Aug 11, 2006 at 11:08:58AM -0700, Allan Bailey wrote:
> Does anyone have an example of how to handle data from an http PUT method?
> So far I'm only getting partial data from the below example.
> Note: I'm fairly new to twisted and using deferred's.  So if I'm missing something
> please let me know, or send pointers.
> thanks,
> -allan
>         data = req.stream.read()

This only reads the data that is immediately available, if no data is
immediately available it returns a deferred that results in the data.
Only calling read once can not possibly guarantee that all the data
has been read.  Instead you need to call read until it returns None.
Luckily there is a convenience API for doing just that.

from twisted.web2.stream import readStream

data = []

def gotData(newdata):
    data += newdata

d = readStream(req.stream, gotData)

def _finishedReading(ignore):


>     def http_PUT(self, req):
>         return self.render_PUT(req)

This seems silly.


"Usually the protocol is this: I appoint someone for a task,
which they are not qualified to do.  Then, they have to fight
a bear if they don't want to do it." -- Glyph Lefkowitz

More information about the Twisted-web mailing list