传递具有自定义异常的对象的正确方法是什么?我很确定这段代码曾经可以工作,但现在它抛出了一个错误。
class FailedPostException(Exception):
pass
def post_request(request):
session = requests.Session()
response = session.send(request.prepare(), timeout=5, verify=True)
if response.status_code is not requests.codes.ok:
raise FailedPostException(response)
session.close()
return response
try:
...
except FailedPostException as r:
// type(r) - Requests.Response
print r.text
AttributeError: 'FailedPostException' object has no attribute 'text'