Baffled by httplib and SSL!

Ray Van Dolson rayvd at
Mon Dec 3 21:07:11 EST 2001

I'm having some real frustrating problems making an HTTPS client using 
httplib.  Here's the code I've got and the errors I'm getting:

def post_url2(url, params, cookies = None):
    """Another feeble attempt"""
    global DEBUG
    h = httplib.HTTPSConnection('')
    params = urllib.urlencode(params)
    headers = {'Content-Type': 'application/x-www-form-urlencoded'}
    if cookies != None:
        cookieString = cookies.pop(0)
        for cookie in cookies:
            cookieString = cookieString + "; " + cookie
        headers['Cookie'] = cookieString
    h.request('POST', url, params, headers)
    while 1:
        response = h.getresponse()
        if response.status != 100:
        h._HTTPConnection__state = httplib._CS_REQ_SENT
        h._HTTPConnection__response = None
    return response

post_url2("https://blahblah", {"fdsafa": "dfjadja"}, \

Here's the debug output:

send: 'POST HTTP/1.1\r\n'
send: 'Host:\r\n'
send: 'Accept-Encoding: identity\r\n'
send: 'Content-Length: 33\r\n'
send: 'Cookie: SessionTest=enabled\r\n'
send: 'Content-Type: application/x-www-form-urlencoded\r\n'
send: '\r\n'
send: 'Acct_Name=private&Password=private'

And now it just hangs.  Just sits there doing nothing until I hit ctrl-c--
here's the traceback:

Traceback (most recent call last):
  File "./", line 10, in ?
  File "./", line 7, in main
    return common.post_url2
("", {'Acct_Name': 
'private', 'Password': 'private'}, ["SessionTest=enabled"])
  File "./", line 72, in post_url2
    response = h.getresponse()
  File "/usr/lib/python2.2/", line 570, in getresponse
    response = self.response_class(self.sock, self.debuglevel)
  File "/usr/lib/python2.2/", line 98, in __init__
    self.fp = sock.makefile('rb', 0)
  File "/usr/lib/python2.2/", line 607, in makefile
    buf =

As you can see it's hanging at the sock.makefile() line in httplib (within 
the HTTPResponse class).  This appears to be some sort of SSL glitch, but 
I have found almost NO documentation on SSL in Python and really don't 
know where to start.  The posts on Google were far and few between and 
didn't really offer much help.

Has anyone out there worked much with httplib and SSL sites?  Your 
expertise would be greatly appreciated!

Ray Van Dolson

More information about the Python-list mailing list