HTTPConnect & 100 messages...

Ray Van Dolson leovd at pacbell.net
Thu Nov 29 20:12:09 EST 2001


I'm trying to write a generic function that will POST data to an HTTPS 
server using HTTP/1.1 (HTTPConnect from httplib).  The server I'm POSTing 
to is an IIS server and after sending the headers insists on sending an 
HTTP/1.1 100 message to let the client know to "continue" or whatever.  
I've written an expect/telnet script that shows what's going on.  However, 
when I try and do the same thing in Python, it hangs at doesn't seem to 
even catch the 100 message.  Here's the function:

def post_url(url, params = None, cookies = None):
    """This function will use httplib to POST to a url using cookies which
    should be in the form of a list and params which should be a
    parameter string"""

    h = httplib.HTTPSConnection('www.dotster.com')
    h.set_debuglevel(1)
    h.putrequest('POST', url)
    h.putheader('Content-type', 'application/x-www-form-urlencoded')
    h.putheader('Connection', 'keep-alive')
    if params != None:
        params = urllib.urlencode(params)
        h.putheader('Content-Length', "%d" % len(params))
    if cookies != None:
        cookieString = ""
        for cookie in cookies:
            cookieString = cookieString + cookie
        print "get_url(): [cookies] -> %s" % cookieString
        h.putheader('Cookie', cookieString)
    h.endheaders()
    print "Waiting for a response!"
    while 1:
        response = h.getresponse()
        print "Got a response."
        if response.status != 100:
            break
        h._HTTPSConnection__state = httplib._CS_REQ_SENT
        h._HTTPSConnection__response = None
    print response
    raw_input("key")
    h.send(params)
    print h
    response = h.getresponse()
    return response

As you can see, I tried using a hack I saw for this exact same thing, but 
still no go.  Here's the debug output:

>>> common.post_url("https://www.dotster.com/account/login/login.asp", \
      {'Acct_Name': 'private', 'Password': 'private'})
send: 'POST https://www.dotster.com/account/login/login.asp HTTP/1.1\r\n'
send: 'Host: www.dotster.com:443\r\n'
send: 'Accept-Encoding: identity\r\n'
send: 'Content-type: application/x-www-form-urlencoded\r\n'
send: 'Connection: keep-alive\r\n'
send: 'Content-Length: 33\r\n'
send: '\r\n'
Waiting for a response!

And it sits here and does nothing.  How can I force it to read from the 
server?  Or better yet send to the server?

Thanks for any ideas,
Ray Van Dolson



More information about the Python-list mailing list