473,769 Members | 7,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BaseHTTPServer fails POST requests: disconnected by peer; maybe sockets bug? help!?

Peace, Pythonphiles!

Python's std lib BaseHTTPServer: I'm stuck with a nasty spoiler -- I
get erratic "Network error: disconnected by peer" for _POST_ requests
only.

=Background=

I'm developing a Python CGI app. Was using Xitami, which is really
light and nice, reasonable performance (circa 200-300 msec to respond,
I guess mostly to start a Python process; localhost; win95 (retch!)).

But, deployed site is the usual Apache/Linux monstrosity. And I wanted
to use mod_rewrite, to export nice URLs. Xitami is inflexible about
URL associations with scripts.

So I tried hacking a python22/libs/SimpleHTTPServe r to "simulate"
Apache's mod_rewrite. It's unbelievable easy!

=The problem=

GET requests work fantastically! 40-100 millisecs to render response
in HTML -- I was really surprised!

But POST requests fail: the script runs ok, response fully generated
and written to stdout, but somewhere while rendering Netscape aborts
with that "Network error: lost connection, disconnected by peer".

This is erratic: sometimes not a character was displayed before it
disconnects, and sometimes the entire page _except the last line_.

These tools are of course buggy as hell, and I learned to "live" with
their limitations during the years, but this one really gets me down:
I want to use Python's *HTTPServer to experiment with FCGI and a
standalone, dedicated Web server for this application, and the
performance was so nice, and _I haven't a clue as to why this strange
behavior occurs_!

Help!!!

=Details=

Invoking script:

sys.stdout = self.wfile
sys.stdin = self.rfile
execfile( "my_cgi.py" , {} )

with both in/out set to _no buffering_:

rbufsize = 0
wbufsize = 0

(Actually, more like

sys.stdout = cgi_output = StringIO.String IO()
#...
self.send_respo nse( status )
self.wfile.writ e( cgi_output.getv alue() )

so can (keep a log and) scan the script's output for a "Status:"
header, aka "parsed-headers CGI" -- I'm simulating Apache, right?)

I tried pausing just before exiting the request handling call:

time.sleep( 25 ) # Trying to get smart with bug?

and it _sometimes_ helps! ie, Netscape renders the page, then gives up
on waiting for the connection to close, I guess, so... there.
But, unreliable.

=Guess?=

I've no idea where to look -- what's different between a GET and
POST?!

It's probably some Micrapsoft buffoonery with sockets.
I really like to patch this somehow.

Any suggestions about how to find the exact point of failure?
Thanks!
-- M
Jul 18 '05 #1
0 1869

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1788
by: Simon Wittber | last post by:
BaseHTTPServer uses the mimetools module, which is deprecated. Are the maintainers of modules that are in the standard library listed somewhere? Who could/should I send patches to? Also, does anyone else find using the email module to decode HTTP POST multipart data a bit weird? Are there any significant differences between parsing HTTP POST requests and email messages, which would warrant a special module for HTTP?
5
3145
by: Jan Roland Eriksson | last post by:
Some more fine tuning and inclusion of last suggested text from regulars has been done to this test post #4 of the mFAQ. As usual, rip it up anywhere you feel that it's appropriate to do so. ===== Archive-name: www/stylesheets/newsgroup-faq Posting-Frequency: once a week Last-modified: 2004-07-26
3
15142
by: James Yang | last post by:
Hi, I am using Sockets to connect to a remote computer and send data using Socket.Send() and receive using Socket.Receive() (block mode) . for somereason tho, when the client disconnects the Socket.Receive() just passes without any exception. Is there any way to detect disconnection using Sockets? I believe I saw a way of doing this using IAsyncResult, and eventhandling but..no article really explained how to use it properly.
33
3960
by: n00m | last post by:
import socket, thread host, port = '192.168.0.3', 1434 s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect((host, 1433)) s1.bind((host, port)) s1.listen(1) cn, addr = s1.accept() def VB_SCRIPT():
5
9628
by: Brian | last post by:
We are having some problems administering HADR on a new installation. Specifically, we are seeing that the connection status of the pair is "disconnected". We have restarted, restored, and even rebooted to no avail. In the diag log we are seeing lots of "External Comm Error". The machines can see each other on the network, and in fact we can start HADR on both machines from the primary (without specifying BY FORCE). Once HADR is...
13
2667
by: Ron Garret | last post by:
I'm trying to figure out how to use BaseHTTPServer. Here's my little test app: ================================= #!/usr/bin/python from BaseHTTPServer import * import cgi
3
2404
by: Ron Garret | last post by:
I have a fairly large web app written in Python as a CGI fairly elaborate CGI. All of the requests go through a single CGI script which does authentication and session management and then dispatches to one of a number of handlers that generate the various pages. There is one page that is a performance bottleneck (because it is accessed automatically once a second by an XMLHTTPRequest, but that's another story). I have fixed this by...
0
1420
by: Avinash Vora | last post by:
On Aug 4, 2008, at 10:44 AM, Trevor Slocum wrote: I've had this problem too. Well, I have about the same level of experience that you do, but I'll take a look at the code and see if I can offer assistance.
1
3829
by: James | last post by:
Hi all, I'm writing a super simple little debugging HTTP server which simply returns the path and parameters it receives requests for. E.g. requesting /meth?a=b returns something like: Command: GET Path: /meth Params: {'a': } This is fine for GET, but I can't see how I access parameters passed
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10048
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.