草庐IT

fnon-call-exceptions

全部标签

python - 当客户端过早断开连接时,如何对 Flask 上的破损管道错误进行异常(exception)处理?

我正在使用flask进行开发,而不是生产,我有一个ajax请求的View,如下所示:@application.route('/xyz//',methods=['GET'])defgetAjax(var):...returnrender_template(...)我还在使用threaded=true进行开发。每当我调用该ajax请求然后关闭请求它的选项卡时,我都会收到错误消息:Traceback(mostrecentcalllast):File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/S

python - 我得到 "TypeError: exceptions must derive from BaseException"即使我确实定义了它

根据python文档,Exception派生自BaseExceptions,我应该将它用于用户定义的异常。所以我有:classVisaIOError(Exception):def__init__(self,error_code):abbreviation,description=_completion_and_error_messages[error_code]Error.__init__(self,abbreviation+":"+description)self.error_code=error_code和raise(visa_exceptions.VisaIOError,stat

python - spyder matplotlib UserWarning : This call to matplotlib. use() 无效,因为已经选择了后端

所以我正在尝试编写一段代码来创建图形,但是为了让它在我想要的计算机(学校计算机)上运行,我不能使用x-window后端来创建图形。我尝试切换后端使用(我的代码中有matplotlib.use('Agg')语句),但每当它创建图形时,当我只想要一个时,它会在图形上给我3个颜色条。它还给我错误UserWarning:Thiscalltomatplotlib.use()hasnoeffectbecausethebackendhasalreadybeenchosen;matplotlib.use()mustbecalled*before*pylab,matplotlib.pyplot,orma

Python - requests.exceptions.SSLError - dh key 太小

我正在使用Python和请求抓取一些内部页面。我已经关闭了SSL验证和警告。requests.packages.urllib3.disable_warnings()page=requests.get(url,verify=False)在某些服务器上,我收到无法通过的SSL错误。Traceback(mostrecentcalllast):File"scraper.py",line6,inpage=requests.get(url,verify=False)File"/cygdrive/c/Users/jfeocco/VirtualEnv/scraping/lib/python3.4/si

Python:subprocess.call 破管

我试图在python中调用一个shell脚本,但它一直报告brokenpipe错误(结果没问题,但我不想在STDERR中看到错误消息)。我已经查明了原因,它可以重现为以下片段:subprocess.call('cat/dev/zero|head-c10|base64',shell=True)AAAAAAAAAAAAAAAA==猫:写入错误:管道损坏/dev/zero是一个无限流,但是head-c10只从中读取10个字节就退出了,然后cat会因为peer而得到SIGPIPE已关闭管道。在shell中运行命令时没有brokenpipe错误消息,但为什么python显示它?

python - Django 自定义模型字段 : to_python() not called

我是Python和Django的新手,也是StackOverflow的新手,所以我希望我不会在这里违反任何规则,我尊重问题格式。我在尝试使用Django(Python3.3.0、Django1.5a1)实现自定义模型字段时遇到问题,但我没有找到任何类似的主题,我实际上很纠结于这个...所以有一个玩家,他有一张手牌。Hand继承自CardContainer,它基本上是具有一些(此处隐藏的)辅助函数的卡片列表。下面是相应的代码:fromdjango.dbimportmodelsclassCard:def__init__(self,id):self.id=idclassCardContain

python - 抽象类的错误 "__init__ method from base class is not called"

我有classA(object):def__init__(self):raiseNotImplementedError("A")classB(A):def__init__(self):....和pylint说__init__methodfrombaseclass'A'isnotcalled很明显,我不想做super(B,self).__init__()那我该怎么办?(我尝试了abc并得到了Undefinedvariable'abstractmethod'来自pylint,因此这也不是一个选项)。 最佳答案 忽略pylint。它只是一

python - 为什么建议从 Exception 派生而不是 Python 中的 BaseException 类?

Python2documentation说“鼓励程序员从Exception类或其子类之一派生新的异常,而不是从BaseException”。没有进一步解释原因。我很好奇为什么会这样推荐?是否只是为了保留exceptionshierarchy正如Python开发人员所设想的那样?>>>dir(BaseException)==dir(Exception)True 最佳答案 从BaseException派生的异常是:GeneratorExit、KeyboardInterrupt、SystemExit。根据文档:GeneratorExit:

Python、Scrapy、管道 : function "process_item" not getting called

我有一个非常简单的代码,如下所示。抓取没问题,我可以看到所有生成正确数据的print语句。在Pipeline中,初始化工作正常。但是,process_item函数不会被调用,因为函数开头的print语句永远不会执行。蜘蛛:comosham.pyimportscrapyfromscrapy.spiderimportSpiderfromscrapy.selectorimportSelectorfromscrapy.httpimportRequestfromactivityadvisor.itemsimportComoShamLocationfromactivityadvisor.items

python - 其他选项而不是使用 try-except

当文本文件中的第2行有'nope'时,它将忽略该行并继续下一行。有没有不使用try和except的另一种写法?我可以使用ifelse语句来执行此操作吗?文本文件示例:0102nope1325nope代码:e=open('e.txt')alist=[]forlineine:start=int(line.split()[0])target=int(line.split()[1])try:ifline.split()[2]=='nope':continueexceptIndexError:alist.append([start,target]) 最佳答案