0

我正在尝试使用 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: ''

4

1 回答 1

0

httplib.BadStatusLineissa 的子类HTTPException。如果服务器以我们不理解的 HTTP 状态代码响应,则引发。这就是导致你的问题的原因。不过,我并不完全确定修复,因为您的代码在我的计算机上运行良好。

于 2012-10-17T05:29:34.367 回答