python的ConnectionError求助
def _request(self, task, entry, method, url, **kwargs):try:
return task.requests.request(method, url, **kwargs)
except Exception as e:
if url in , entry['base_url']]:
entry['result'] = SignState.NETWORK_ERROR.value.format(str(e))
else:
entry['messages'] = SignState.NETWORK_ERROR.value.format(str(e))
return None
我已经这样捕获Exception了 为什么有时候还是会出现
File "/root/.flexget/config/plugins/auto_sign_in.py", line 256, in check_state
content = self._decode(response, (entry['encoding']))
| | | -> <Entry(title=haidan 2020-04-19,state=accepted)>
| | -> <Response >
| -> <function PluginAutoSignIn._decode at 0x7f172ddadc10>
-> <flexget.plugins.auto_sign_in.PluginAutoSignIn object at 0x7f172dd29340>
File "/root/.flexget/config/plugins/auto_sign_in.py", line 280, in _decode
content = gzip.decompress(response.content)
| | | -> <property object at 0x7f172ed9a1d0>
| | -> <Response >
| -> <function decompress at 0x7f172df559d0>
-> <module 'gzip' from '/usr/local/lib/python3.8/gzip.py'>
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 828, in content
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
| | | | -> 10240
| | | -> <function Response.iter_content at 0x7f172ed9b550>
| | -> <Response >
| -> False
-> <Response >
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 757, in generate
raise ConnectionError(e)
-> <class 'requests.exceptions.ConnectionError'>
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.haidan.cc', port=443): Read timed out.
我该如何正确的捕获这个异常?
{:1_890:} 我还是个初学者,看不太明白你的代码。不过如果是要失败重连的话,可以参考
https://blog.csdn.net/guliang21/article/details/89207481 rsnodame 发表于 2020-4-20 10:29
我还是个初学者,看不太明白你的代码。不过如果是要失败重连的话,可以参考
https://blog.csdn. ...
感谢回复,不过不是想失败重连,我是想捕获这个异常,不然程序就停止了 madwind 发表于 2020-4-20 17:45
感谢回复,不过不是想失败重连,我是想捕获这个异常,不然程序就停止了
我只会把这个错误类直接import,然后捕获{:1_890:} rsnodame 发表于 2020-4-20 19:49
我只会把这个错误类直接import,然后捕获
我已经直接捕获了Exception 理论上不是应该所有异常都被捕获了吗 except Exception as e:
改成:
except:
试一下。
页:
[1]