假设我有以下3个脚本:
script1.py
script2.py
script3.py
让我说我得到了这样的回溯:
Traceback (most recent call last):
File "script1.py", line xyz, in ...
...
File "script2.py", line xyz, in ...
...
File "script3.py", line xyz, in ...
...
AttributeError: 'NoneType' object has no attribute
在Python3中,有一个来重新引发异常。也就是说,如何从引发的异常中找到原始的(/重新引发的)异常?这里有一个(愚蠢的)例子,上面有一些评论来说明我的意思--
def some_func():
try:
None() # TypeError: 'NoneType' object is not callable
except as err:
raise Exception("blah") from err
try:
some_func()
except as err:
# how can I access
我的框架的用户(他们可能精通Python,也可能不熟悉Python)编写了导航dict (最初来自某个API的json响应)的代码。
有时他们犯了错误,有时API返回一些值丢失的数据,他们得到了可怕的'NoneType' object is not subscriptable。
如何明确错误发生在哪个级别?(什么密钥没有返回)
def user_code(some_dict):
# I can't modify this code, it is written by the user
something = some_dict["a"][
当我的(python2.7)程序退出时,我得到了许多被忽略的异常。但是由于项目规模很大,而且是基于别人开发的项目,所以很难用这样的信息来定位bug。有没有办法获得异常跟踪,或任何其他方法,可以帮助?谢谢。
Exception TypeError: "'NoneType' object is not callable" in <object repr() failed> ignored
Exception TypeError: "'NoneType' object is not callable" in <obje
当使用throws关键字抛出一个自定义异常时,我需要显式地处理它,也就是说,我需要在try-catch块中调用该方法,但是当我使用throws关键字抛出一个内置异常时,如果我没有使用try-catch块在main方法中处理它,那么我不会得到任何编译时错误,运行时异常发生是可以接受的。我的问题是,当我不处理自定义异常时,我会得到一个编译时错误:未处理的异常。虽然这不是内置异常的情况
class B
{
public void show() throws ArithmeticException
{
throw new ArithmeticException();
我提取从第三方服务器接收的数据:
data = json.loads(response)
if data:
result = data.get('result')
if result and len(result)>=38 and len(result[38])>=2:
for item in result[38][2]:
...
该条件的思想是检查列表中是否包含具有索引38 (result[38])的元素和带有索引2 (result[38][2])的子元素,但是看起来它不起作用,因为我得到了以下异常-
>=
我不能运行['abc'].append( MyModel.objects.all() ),因为如果MyModel没有条目,它会生成异常'NoneType' object is not iterable。
任何解决办法或类似于? : in c++的东西
编辑:我的语句实际上是
','.join([ str(e) for e in ['abc','def'].append( MyModel.objects.all() ) ])
这个问题似乎是由append()返回NoneType引起的。我通过创建一个变量来保存列表,然
我有一个超过2000行的python脚本,它是通过生产服务器上的以下异常处理的,我不能在本地重现这个问题来调试它,我也不知道它是从哪里来的。
Exception TypeError: TypeError("argument of type 'NoneType' is not iterable",) in <bound method Popen3.__del__ of <popen2.Popen3 instance at 0x7fccba7b65f0>> ignored
Exception TypeError: TypeError("
我已经把一些代码上传到服务器上了。代码在本地工作,但当我将其上传到服务器时,它会给我一个Internal Server Error。该网站与wsgi一起运行,代码是:
try:
from decksite import main, APP as application
except Exception as e:
from shared import repo
repo.create_issue('Error starting website', exception=e)
if __name__
我有以下代码:
# exc is a local variable of type Exception
# This is not inside an except block
if isinstance(exc, ClientError):
logging.debug("ClientError raised while loading %s:\n%s", package.id, traceback.format_exc())
continue
当运行此代码且exc类型为ClientError时,format_exc()只打印出NoneType: None,因为
在Python2.7.5中,在except:块中屈服时,我注意到了一些奇怪的行为:
def generator():
try:
raise Exception()
except:
yield
raise
list(generator())
此代码在TypeError: exceptions must be old-style classes or derived from BaseException, not NoneType中失败
为什么Python要这样做,而不是像yield在raise之前那样重新引发异常呢?
(显然Pyt
我有一个在1中开发的项目,这个项目已经完成。
现在,当我测试整个网站时,有些页面会抛出异常。其中之一如下:
异常'Zend_Paginator_Exception‘,并带有消息'No adapter for type NULL’
我已经在网上搜索,并得到了步骤,以添加尝试-捕捉到这个。但是,检查所有代码并重复此步骤将需要很长时间。
我可以编写一个常见的异常处理程序来捕获所有异常并处理它吗?
try:
#'NoneType' object has no attribute 'pop'
#'NoneType' object has no attribute 'lower'
except TypeError:
#this code should run if any of the two errors happens, but doesn't
#right now it doesn't OFC
except Exception as e:
input(e)
下面是python 中所有
我尝试添加我的处理程序来向电报发送错误。我创建了自己的处理程序: #myLogHandlers.py
import logging
from config import config
from pyrogram import Client
from time import time, sleep
logger = logging.getLogger(__name__)
class TelegramHandler(logging.Handler):
"""Loggig handler for sending logs to telegram"
我正在尝试处理两个变量都等于None的TypeError异常。
我想让它们每一个都等于一个浮点型0。如果其中一个变量为float,另一个为NoneType,它似乎可以正确地将NoneType变量转换为0并返回float,但当这两个变量都为NoneType时,我仍然会收到类型错误
'<' not supported between instances of 'float' and 'NoneType'
为什么会发生这种情况?我期望下面的函数返回0。下面是我的代码:
def test():
market_price = None
在尝试将AutoMapper实体解析为视图模型时,我一直会遇到异常,但我不知道原因。
以下代码
Mapper.CreateMap<Article, ArticleViewModel>()
.ForMember(a => a.CreatedDate, a => a.ResolveUsing<DateResolver>())
.ForMember(a => a.Content, a => a.ResolveUsing<ContentResolver>().ConstructedBy(() =>
new Con
我正在捕获异常,对于特定的异常类和该类中的错误代码,我会进行一些自定义处理。对于所有其他异常,我希望使用通用错误处理程序。如下所示:
on E:EADSDatabaseError do
begin
case E.ACEErrorCode of
5132:
begin
//Custom handling
end;
else
begin
raise;
end;
end;
end;
on E:Exception do
begin
嗨,我试着从这个站点实现解决方案,我的WPF应用程序用于全局异常处理。
我使用卡利伯恩微作为MVVM框架。服务,我在外部组装,它是注入视图模型类与MEF。
下面是我在WPF应用程序中全局异常处理的实现。
App.xaml
DispatcherUnhandledException="Application_DispatcherUnhandledException"
Startup="Application_Startup"
App类:
public partial class App : Application
{
p