草庐IT

exception_class

全部标签

python - 如何调试 "Exception while resolving variable in template ' 未知'”?

我一直在看DEBUGExceptionwhileresolvingvariable'exception_type'intemplate'unknown'.在我的django日志中,然后是VariableDoesNotExist:Failedlookupforkey[exception_type]in后跟看起来像是包含请求的字典列表的字符串表示形式,以及我的整个settings.py文件。另一个例子:DEBUGExceptionwhileresolvingvariable'lastframe'intemplate'unknown'我觉得我只是没有足够的信息来调试它。我所知道的是未知模板中

python - 为什么 Python 的 `except` 不使用 `isinstance` ?

Pythondocumentation对于except说:Foranexceptclausewithanexpression,thatexpressionisevaluated,andtheclausematchestheexceptioniftheresultingobjectis“compatible”withtheexception.Anobjectiscompatiblewithanexceptionifitistheclassorabaseclassoftheexceptionobject,[...]为什么except不使用isinstance而不是比较基类?这会阻止使用__

python - Networkx read_gml 错误 "networkx.exception.NetworkXError: cannot tokenize u' 图在 (3, 1)”

我正在尝试使用networkx读取gml文件(很简单吧?),除非我尝试读取文件时出现错误“networkx.exception.NetworkXError:cannottokenizeu'graph'at(3,1)"我对gml或networkx不太熟悉,所以我无法自己诊断问题。更奇怪的是,我的同事将使用完全相同的文件运行完全相同的命令,而且它会毫无错误地执行。此时我已经多次卸载并重新安装networkx,任何人都可以帮助确定错误可能来自什么?importnetworkxasnxg=nx.read_gml('disciplineNetwork.gml')追溯(最近的调用最后):File"

python - 将字符串转换为字典,然后访问 key :values? ??如何为 Python 访问 <class 'dict'> 中的数据?

我在访问字典中的数据时遇到问题。Sys:Macbook2012Python:Python3.5.1::ContinuumAnalytics,Inc.我正在使用dask.dataframe从csv创建。编辑问题我是如何走到这一步的假设我从Pandas系列开始:df.Coordinates130{u'type':u'Point',u'coordinates':[-43.30175...278{u'type':u'Point',u'coordinates':[-51.17913...425{u'type':u'Point',u'coordinates':[-43.17986...440{u'

python - 如何修复 ValueError : read of closed file exception?

这个简单的Python3脚本:importurllib.requesthost="scholar.google.com"link="/scholar.bib?q=info:K7uZdMSvdQ0J:scholar.google.com/&output=citation&hl=en&as_sdt=1,14&ct=citation&cd=0"url="http://"+host+linkfilename="cite0.bib"print(url)urllib.request.urlretrieve(url,filename)引发此异常:Traceback(mostrecentcalllas

c++ - 我可以在 python 类中使用 C++ 类作为父类(super class)吗

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:HowcanIuseC++classinPython?我正在用python设计一个软件,但在用python实现它时遇到了一些内存问题,所以我计划用C++扩展我的软件。所以我在想我可以使用C++定义的类并在python中将它用作父类(superclass)并覆盖它的一些方法吗?

python - 如何向 _not_ 继承的 python *class* 添加属性?

我需要能够在子类不可见的类(不是类的实例)上设置一个标志。问题是,这可能吗?如果可能,我该怎么做?为了说明,我想要这样的东西:classMaster(SomeOtherClass):__flag__=TrueclassChild(Master):pass...其中hasattr(Master,"__flag__")应该为Master返回True但False为child。这可能吗?如果是这样,如何?我不想在每个child中都将__flag__显式设置为false。我最初的想法是定义__metaclass__,但我没有那么多奢侈,因为Master继承自一些我无法控制的其他类和元类哪些是私有

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 - 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