我试图使用Python中的机器库打开一个安全的(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'例外:
回溯(最近一次调用):pydev_imports.execfile文件(文件、全局文件、局部变量)#在resp=br.open('https://incometaxindiaefiling.gov.in/portal/index.do')中执行脚本文件"Z:\pyTax\app_test.py",第22行 文件"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行,在"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 BadStatusLine(行)httplib.BadStatusLine中:'‘
发布于 2012-10-17 05:29:34
httplib.BadStatusLineis是HTTPException的一个子类。如果服务器使用我们不理解的HTTP状态代码进行响应,则引发。这就是导致你问题的原因。不过,我并不完全确定修复程序,因为您的代码在我的计算机上运行得很好。
https://stackoverflow.com/questions/12927516
复制相似问题