Baffled by httplib and SSL!
Steve Holden
sholden at holdenweb.com
Mon Dec 3 22:09:37 EST 2001
"Ray Van Dolson" <rayvd at pacbell.net> wrote...
> 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('www.dotster.com')
> h.set_debuglevel(DEBUG)
> 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:
> break
> h._HTTPConnection__state = httplib._CS_REQ_SENT
> h._HTTPConnection__response = None
> return response
>
> post_url2("https://blahblah", {"fdsafa": "dfjadja"}, \
> ["SessionTest=enabled"])
>
> Here's the debug output:
>
> 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-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'
>
Since I am not yet using this library I will limit my observation to the
fact that the scheme (https:) and the host (//www.dotster.com) are normally
implied by a) the connection port (443 by default) and b) the connected
host. I would therefore have expected the first line to be
send: 'POST /account/login/login.asp HTTP/1.1\r\n'
but I don't know if this is what's causing your problem.
regards
Steve
> 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 "./test.py", line 10, in ?
> main()
> File "./test.py", line 7, in main
> return common.post_url2
> ("https://www.dotster.com/account/login/login.asp", {'Acct_Name':
> 'private', 'Password': 'private'}, ["SessionTest=enabled"])
> File "./common.py", line 72, in post_url2
> response = h.getresponse()
> File "/usr/lib/python2.2/httplib.py", line 570, in getresponse
> response = self.response_class(self.sock, self.debuglevel)
> File "/usr/lib/python2.2/httplib.py", line 98, in __init__
> self.fp = sock.makefile('rb', 0)
> File "/usr/lib/python2.2/httplib.py", line 607, in makefile
> buf = self.__ssl.read()
> KeyboardInterrupt
>
> 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!
>
> Thanks,
> Ray Van Dolson
More information about the Python-list
mailing list