gpt4 book ai didi

python - 为什么这个 `try` 语句没有捕获这个 `CannotSendRequest` 错误? Python

转载 作者:行者123 更新时间:2023-11-28 17:40:26 26 4
gpt4 key购买 nike

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

括号中的tx 是即将广播到网络的原始交易。这是结果-

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

提前致谢:)

编辑:

为了论坛的缘故,我最初缩短了错误,但现在我已经用完整的错误输出更新了它。再次感谢:)

编辑2:

我刚刚看到我在上面的主帖中添加的 try 语句中有一个 raise。通常报告的错误是“raise cannot be None”或类似的东西,但这不是我这次看到的。我会提到它以某种方式重新发明。

最佳答案

raise 自身重新引发捕获的异常,保留其堆栈跟踪。如果您不想传播异常,请删除 raise

您在问题中描述的内容仅在没有处理任何异常且仅在 Python 2 中使用裸 raise 时才会发生:

Usually the error reported by this is that 'raise cannot be None' or something to that effect

确切的错误是:

TypeError: exceptions must be old-style classes or derived from BaseException, not NoneTyp e

.在 Python 3 中,它更具体:

RuntimeError: No active exception to reraise

……但同样,这不应该应用于 except block 。

关于python - 为什么这个 `try` 语句没有捕获这个 `CannotSendRequest` 错误? Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25194745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com