python - 异常返回无
问题描述
我想在调用函数时捕获错误。例如,互联网已经消失。我这样做:
def get_position(self) -> position.Position:
result = position.Position()
try:
return result.json_parse(self.client.futures_position_information(symbol=SYMBOl))
except Exceptione:
print(f'err: GET_POSITION {e}')
time.sleep(5)
self.get_position()
互联网出现后。该函数返回无。我明白这是不正确的。怎么做才对?
解决方案
不要递归调用函数
def get_position(self) -> position.Position:
while True:
result = position.Position()
try:
return result.json_parse(self.client.futures_position_information(symbol=SYMBOl))
except Exceptione:
print(f'err: GET_POSITION {e}')
time.sleep(5)
推荐阅读
- javascript - 如何仅读取 Firebase 实时数据库中的更改
- python - 如何使用 R 或 Python 提取我需要的 netCDF/nc 数据?
- firebase - 在flutter中使用2个where子句查询Firestore
- flask - validate_on_submit (flask-wtf) 不工作
- c++ - 如何在 ax_boost_base 中使用 HAVE_BOOST
- azure-storage - 如何使用 ADLS gen 2 容器的访问策略生成 SAS 令牌
- reactjs - 如何随机化 qraphql 查询结果?
- android -
- 内部元素必须是资源引用或为空
- reactjs - ReactJS - 如何使用 React Router 创建具有单路径的多步组件/表单
- bash - 按顺序合并同名多部分pdf文件