BaseHTTPServer & TCP Reset
Scherer, Bill
Bill.Scherer at VerizonWireless.com
Thu Jan 24 10:32:57 EST 2002
On Thu, 24 Jan 2002, Steve Holden wrote:
> "Scherer, Bill" <Bill.Scherer at VerizonWireless.com> wrote in message
> news:mailman.1011884317.31625.python-list at python.org...
> >
> > I'm having a problem with an application using BaseHTTPServer.
> >
> > Certain results coming from one method in the application will
> > cause a reset at the tcp level. This is causing great headaches,
> > for in IE 5.0, the user is simply warned of the connection reset
> > and left at that.
> >
> > IE 5.5 however, upon receiving the reset, will rePOST the
> > request. Soetimes it even does a third resubmit, only as a GET
> > request. !?!?!?!?!?
> >
> > The behavior is repeatable. The response data is html, with
> > proper headers, content-length, etc. Python is v2.1.1, and OS is
> > RH Linux 6.2.
> >
> > Any help is greatly appreciated.
> >
> > Thanks!
> >
> It's probably line 3 of your method terminating the output early :-)
>
> A little more context might be helpful in debugging this problem. Are you
> absolutely POSITIVE that the Content-Length: header is correct? I've seen
> this odd behavior from IE in the past, and ISTR it was associated with
> output length.
>
> Anyway, perhaps if we needed our psychic powers less, we could be more
> helpful.
Yeah, I expected that. But at least I've got the conversation
started...
I am fairly certain the content length is correct; all app
methods respond via the same code. Only the html from this one
particular method has problems, and only for certain inputs.
When it does happen, a view source on the client (before the auto
re-submit) shows the complete source. Sometimes the client sits
there for a minute or two before it resubmits ( a wait cursor
whilst hovering over the titlebar is an indicator that it will
re-submit in the near future).
Also, I've tried it without setting content length at all (if i
read the spec correctly, that's allowed; the client is supposed
to know that it's done when the server closes the connection),
and that didn't change the behavior.
I've tried alter my respond code in many ways, with waits and
flushes, but nothing seems to help. Here's what it looks like:
def respond(self, html, ctype='text/html', fname=None):
self.length = len(html)
baseType = ctype.split('/')[0]
if (baseType == 'text') and (type(html) != types.StringType):
html = repr(html)
expiration = time.strftime("%a, %d %b %Y %H:%M:%S GMT", \
time.gmtime(time.time()))
try:
self.send_response(200)
self.send_header("Content-Type", ctype)
self.send_header("Content-Length", self.length)
self.send_header("Expires", expiration)
self.send_header("Connection", "Close")
if fname:
self.send_header("Content-Disposition", \
'inline; filename=%s' % fname)
self.end_headers()
self.wfile.write(html)
time.sleep(.1)
self.wfile.flush()
except IOError:
#client connection has gone away... 8-(
pass
Again, I'm reponding with this code from all the other methods
without issue, send csv's, pdf's, and html. Given that I'd
suspect the actual html from the instances where it goes wrong,
but I've looked at that, and I can't see anything that would
cause a server reset...
>
> regards
> Steve
> --
> Consulting, training, speaking: http://www.holdenweb.com/
> Python Web Programming: http://pydish.holdenweb.com/pwp/
>
>
>
>
>
>
--
Bill.Scherer at Verizon Wireless
RHCE 807101044903581
More information about the Python-list
mailing list