简体   繁体   中英

'Resource Temporarily Unavailable' after POST http request is received - Python

I am having problem with my server socket. I am making a web server and trying to fill a from a browser. The form HTML script is as shown:

<html>
<body bgcolor = black text= white>
<FORM method="post" action="/processData.py">
<P>
<LABEL for="firstname">First name: </LABEL>
<INPUT type="text" id="firstname"><BR>

<LABEL for="lastname">Last name: </LABEL>
<INPUT type="text" id="lastname"><BR>

<LABEL for="email">email: </LABEL>
<INPUT type="text" id="email"><BR>

<INPUT type="radio" name="sex" value="Male"> Male<BR>
<INPUT type="radio" name="sex" value="Female"> Female<BR>

<INPUT type="submit" value="Send"> <INPUT type="reset">
</P>
</FORM>
</body>
</html>

i am trying to print the entire request on my terminal when a POST request is sent from the browser after hitting 'submit'. when i receive the POST request on my web server, the socket throws a '[Errno 35] Resource Temporarily Unavailable'. I am not closing the connection or anything but somehow i am loosing connection. Here is the code i am using in python to get POST.

while not recvIsComplete:
    rcvdStr = fd.recv( 1024 )
    if rcvdStr[0:3] == "GET":
        toGET()

    elif rcvdStr[0:4] == "POST":       
        print rcvdStr

Any idea whats going on?

This may not be correct, but it seems most likely based on the information you've given:

You've written a blocking server—probably each client connection in its own thread (but maybe using processes or greenlets instead, or maybe even just only handling one client at a time). But you're using non-blocking sockets.

The details depend on your exact code and platform, but the most common reason to get this is that you called recv on a non-blocking socket with no data on it, and it's returning EWOULDBLOCK , and your platform has the same error number for EAGAIN and EWOULDBLOCK .

If so, the easy answer is: don't use non-blocking sockets with a blocking server. Either make sure the sockets are in blocking mode, or don't call recv on them unless you know there's data (eg, because select just told you so).

You can handle non-blocking sockets in a blocking server by try ing the recv and handling the EWOULDBLOCK in some way (eg, select on just that socket and try again, or send a heartbeat/idle packet to make sure the other side is still there, or whatever is appropriate for your design). But usually, that's not what you want to do; you can do something simpler with settimeout .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM