我正在尝试使用 Python 中的 mechanize 库打开一个安全(https)网站。当我尝试访问该网站时,服务器会关闭连接并引发异常 BadStatusLine。
我尝试使用该addheaders
属性修改标题,但没有响应。
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'
例外:
Traceback(最近一次调用最后一次): File pydev_imports.execfile(file, globals, locals) #执行脚本 File "Z:\pyTax\app_test.py", line 22, in resp=br.open('https:// incometaxindiaefiling.gov.in/portal/index.do ')
文件“build\bdist.win32\egg\mechanize_mechanize.py”,第 203 行,打开文件“build\bdist.win32\egg\mechanize_mechanize.py”,第 230 行,在 _mech_open 文件“build\bdist.win32\egg\mechanize_opener.py”,第 188 行,在打开文件“build\bdist.win32\egg\mechanize_http.py”,第 316 行,在 http_request 文件“build\bdist.win32 \egg\mechanize_http.py”,第 242 行,在读取文件“build\bdist.win32\egg\mechanize_mechanize.py”,第 203 行,打开
文件“build\bdist.win32\egg\mechanize_mechanize.py”,第 230 行,在 _mech_open 文件“build\bdist.win32\egg\mechanize_opener.py”,第 193 行,在打开文件“build\bdist.win32\egg\ mechanize_urllib2_fork.py”,第 344 行,_open 文件“build\bdist.win32\egg\mechanize_urllib2_fork.py”,第 332 行,_call_chain 文件“build\bdist.win32\egg\mechanize_urllib2_fork.py”,第 1170 行,在 https_open文件“build\bdist.win32\egg\mechanize_urllib2_fork.py”,第 1116 行,在 do_open 文件“D:\Python27\lib\httplib.py”,第 1031 行,在 getresponse response.begin() 文件“D:\Python27 \lib\httplib.py”,第 407 行,开始版本,状态,原因 = self._read_status() 文件“D:\Python27\lib\httplib.py”,第 371 行,在 _read_status raise BadStatusLine(line) httplib.BadStatusLine: ''