0

I'm trying to open a secure (https) website using mechanize library in Python. When I try to access the website, the server closes the connection and exception BadStatusLine is raised.

I have tried to modify the headers using the addheaders property, but no response.

import mechanize

br = mechanize.Browser()
print 'opening page ...'
resp = br.open('https://onlineservices.tin.nsdl.com/etaxnew/tdsnontds.jsp')     #this one works fine
print 'ok'

print 'opening page 2 ...'
resp = br.open('https://incometaxindiaefiling.gov.in/portal/index.do')          #exception raised 
print 'ok'

Exception:

Traceback (most recent call last): File pydev_imports.execfile(file, globals, locals) #execute the script File "Z:\pyTax\app_test.py", line 22, in resp=br.open('https://incometaxindiaefiling.gov.in/portal/index.do')
File "build\bdist.win32\egg\mechanize_mechanize.py", line 203, in open File "build\bdist.win32\egg\mechanize_mechanize.py", line 230, in _mech_open File "build\bdist.win32\egg\mechanize_opener.py", line 188, in open File "build\bdist.win32\egg\mechanize_http.py", line 316, in http_request File "build\bdist.win32\egg\mechanize_http.py", line 242, in read File "build\bdist.win32\egg\mechanize_mechanize.py", line 203, in open
File "build\bdist.win32\egg\mechanize_mechanize.py", line 230, in _mech_open File "build\bdist.win32\egg\mechanize_opener.py", line 193, in open File "build\bdist.win32\egg\mechanize_urllib2_fork.py", line 344, in _open File "build\bdist.win32\egg\mechanize_urllib2_fork.py", line 332, in _call_chain File "build\bdist.win32\egg\mechanize_urllib2_fork.py", line 1170, in https_open File "build\bdist.win32\egg\mechanize_urllib2_fork.py", line 1116, in do_open File "D:\Python27\lib\httplib.py", line 1031, in getresponse response.begin() File "D:\Python27\lib\httplib.py", line 407, in begin version, status, reason = self._read_status() File "D:\Python27\lib\httplib.py", line 371, in _read_status raise BadStatusLine(line) httplib.BadStatusLine: ''

Catpro
  • 11
  • 2
  • mechanize probably tries to connect with an ssl protocol version which is refused/not supported by the server. – andrean Oct 17 '12 at 05:30
  • your code works fine on my computer, does this only occour when accessing this specific website only or does it happen with others too? – root Oct 17 '12 at 05:52
  • this problem occurs only with specific website, other websites work fine with same code. this website perfectly opens in browsers. – Catpro Oct 17 '12 at 06:03

1 Answers1

0

httplib.BadStatusLineis s a subclass of HTTPException. Raised if a server responds with a HTTP status code that we don’t understand. That's whats causing your problem. I am not entirely sure about the fixup though, as your code works fine on my computer.

root
  • 76,608
  • 25
  • 108
  • 120