简体   繁体   English

为什么这个`try`语句不能捕获这个`CannotSendRequest`错误? 蟒蛇

[英]Why doesn't this `try` statement catch this `CannotSendRequest` error? python

try:
    serial_tx = bcl.sendrawtransaction(tx)
except:
    raise
    ''other stuff''

The tx in the parenthesis is a raw transaction that is about to be broadcast to the network. 括号中的tx是即将广播到网络的原始事务。 This was the result - 这是结果 -

Internal Server Error: /blockscript/0d82f8c8f85ed2b8226dd98ad967c81b00000000000074cfc81b5e3cfdef19975408ef2c2d9976160c69dd2057505d5a/
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 114, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/media/derrend/data/Development/projectone/pro1/views.py", line 1012, in blockscript
    process_rec(tx, L_dct=L_dct, W_dct=W_dct)
  File "/media/derrend/data/Development/projectone/pro1/views.py", line 494, in process_rec
    serial_tx = bcl.sendrawtransaction(tx)
  File "/usr/local/lib/python2.7/dist-packages/python_bitcoinlib-0.2_SNAPSHOT-py2.7.egg/bitcoin/rpc.py", line 403, in sendrawtransaction
    r = self._call('sendrawtransaction', hextx)
  File "/usr/local/lib/python2.7/dist-packages/python_bitcoinlib-0.2_SNAPSHOT-py2.7.egg/bitcoin/rpc.py", line 163, in _call
    'Content-type': 'application/json'})
  File "/usr/lib/python2.7/httplib.py", line 973, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1001, in _send_request
    self.putrequest(method, url, **skips)
  File "/usr/lib/python2.7/httplib.py", line 871, in putrequest
    raise CannotSendRequest()
CannotSendRequest

Thanks in advance :) 提前致谢 :)

EDIT: 编辑:

I originally shortened the error for the sake of the forum but i have updated it with the full error output now. 我最初为了论坛而缩短了错误,但我现在已经用完整的错误输出更新了它。 Thanks again :) 再次感谢 :)

EDIT2: EDIT2:

I just saw that there is a raise in the try statement which I have added to the main post above. 我刚刚看到我在上面的主要帖子中添加的try语句中有一个加注。 Usually the error reported by this is that 'raise cannot be None' or something to that effect but that is not what I'm seeing this time. 通常由此报告的错误是'加注不能是无'或者那种效果,但这不是我现在看到的。 I'll mention in though i case it is reinvent in some way. 我会提到虽然我的情况是它在某种程度上重新发明。

raise on its own re-raises a caught exception, preserving its stack trace. raise自身的重新提出了一个捕获的异常,保持其堆栈跟踪。 If you don't want the exception to be propagated, remove the raise . 如果您不希望传播异常,请删除raise

What you describe in your question only occurs when using a bare raise when there is no exception being handled, and only in Python 2: 您在问题中描述的内容仅在没有处理异常时使用裸raise时发生,并且仅在Python 2中:

Usually the error reported by this is that 'raise cannot be None' or something to that effect 通常,由此报告的错误是“加注不能为无”或类似的结果

the exact error being: 确切的错误是:

TypeError: exceptions must be old-style classes or derived from BaseException, not NoneTyp e TypeError:exception必须是旧式类或派生自BaseException,而不是NoneTyp e

. In Python 3, it's more specific: 在Python 3中,它更具体:

RuntimeError: No active exception to reraise RuntimeError:没有活动的异常来重新加载

… but again, that should never apply in an except block. ......但是,再次,这应该永远不适用于一个except块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM