Title: urllib2 HTTPS connection failure (BadStatusLine Exception)
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.0, Python 2.6
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: ajaksu2, ak, jjlee, orsenthil, shashank
Priority: normal Keywords: easy

Created on 2009-01-19 23:45 by ak, last changed 2009-11-22 15:33 by orsenthil. This issue is now closed.

Messages (4)
msg80224 - (view) Author: (ak) Date: 2009-01-19 23:45 is served by an Oracle HTTPS server, and works
with firefox or opera but not urllib2.

code snippet:

import cookiejar
import urllib2

cookiejar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
url = ''
req = urllib2.Request(url, None)

Here's some output with debuglevel=1 :

>>>'', None, headers))

reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Mon, 19 Jan 2009 21:44:03 GMT
header: Server: Oracle-Application-Server-10g/ Oracle-HTTP-
header: Set-Cookie:
header: Expires: Mon, 19 Jan 2009 21:44:13 GMT
header: Surrogate-Control: max-age="10"
header: Content-Type: text/html; charset=ISO-8859-2
header: X-Cache: MISS from
header: Connection: close
header: Transfer-Encoding: chunked
<addinfourl at 137417292 whose fp = <socket._fileobject object at

>>>'', None, headers))

reply: ''
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/", line 381, in open
    response = self._open(req, data)
  File "/usr/lib/python2.5/", line 399, in _open
    '_open', req)
  File "/usr/lib/python2.5/", line 360, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.5/", line 1115, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.5/", line 1080, in do_open
    r = h.getresponse()
  File "/usr/lib/python2.5/", line 928, in getresponse
  File "/usr/lib/python2.5/", line 385, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.5/", line 349, in _read_status
    raise BadStatusLine(line)

As you can see the reply from the server seems empty (which results in
the BadStatusLine exception)
msg86309 - (view) Author: Daniel Diniz (ajaksu2) (Python triager) Date: 2009-04-22 17:25
Confirmed in 2.5, cannot confirm on trunk. Needs confirmation on 2.6 and
msg91857 - (view) Author: Shashank (shashank) Date: 2009-08-22 07:27
Works fine for me in 2.6 but fails as said by OP on 2.5.
(I came across this in the course of my work and am submitting a change
in a bug for the first time, pardon me if something is inappropriate :)

I used this modified codeblock:

import cookielib
import urllib2

cookiejar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
url = ''
req = urllib2.Request(url, None)


2.6 gives a complete HTML page but 2.5 raises httplib.BadStatusLine
msg95601 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-11-22 15:33
This bug is not reproducible in trunk, py3k and is not reproducible in
py26 releases too. I tried to hunt down if any changes in the code-line
from py2.5 to py2.6 had effect on the behavior mention (BadStatusLine) ,
but don't see any. 

I am closing this as works for me.
Date User Action Args
2009-11-22 15:33:58orsenthilsetstatus: open -> closed
resolution: works for me
messages: + msg95601
2009-08-22 11:06:24orsenthilsetassignee: orsenthil
2009-08-22 07:27:01shashanksetnosy: + shashank
messages: + msg91857
2009-04-22 17:25:04ajaksu2setpriority: normal
versions: + Python 3.0
nosy: + ajaksu2

messages: + msg86309

keywords: + easy
2009-02-13 01:37:12ajaksu2setnosy: + jjlee, orsenthil
stage: test needed
versions: + Python 2.6, - Python 2.5
2009-01-19 23:45:09akcreate