Closed delobanov closed 2 weeks ago
Seems you've investigated the issue a fair bit. Feel free to submit a pull request, as I don't personally use proxies.
If I understand correctly, we need to handle ProxyError
, ProxyConnectionError
, ProxyTimeoutError
errors in places where we already handle IOError
in connection.py
like in recv and send loops like this
https://github.com/LonamiWebs/Telethon/blob/75408483ad44a34553f40c02c375a2567c74831c/telethon/network/connection/connection.py#L328-L355
and in mtprotosender.py
in _try_connect
, _connect
, _reconnect
, _send_loop
and _recv_loop
.
But I don't understand, why IOError
handles when it seems to be already handled, example:
in mtprotosender.py
_reconnect
:
https://github.com/LonamiWebs/Telethon/blob/75408483ad44a34553f40c02c375a2567c74831c/telethon/network/mtprotosender.py#L376-L383
in mtprotosender.py
_connect
:
https://github.com/LonamiWebs/Telethon/blob/75408483ad44a34553f40c02c375a2567c74831c/telethon/network/mtprotosender.py#L232-L255
and then in mtprotosender.py
_try_connect
:
https://github.com/LonamiWebs/Telethon/blob/75408483ad44a34553f40c02c375a2567c74831c/telethon/network/mtprotosender.py#L281-L291
Looks like IOError
already handled in _try_connect
method and handling in _reconnect
seems useless?
Maybe I am missing something? Will handling proxy errors in this places be enough?
Too complicated. I'd make a subclass and use that:
class ConnectionErrorExtra(ConnectionError):
def __init__(self, *args, **kwargs):
super().__init__()
and then we can use this instead of the default ConnectionError
.
Please look for my fix (#4440 ). Is it okay to define Error class right in function? As for error_code argument I make definition like in original python_socks repository.
Is it okay to define Error class right in function?
That's fine. It means people won't import it (or shouldn't), but it's okay because it inherits ConnectionError
.
Code that causes the issue
I found problem in this patch of standard python_socks error.
https://github.com/LonamiWebs/Telethon/blob/75408483ad44a34553f40c02c375a2567c74831c/telethon/network/connection/connection.py#L115-L123
Expected behavior
Error
python_socks._protocols.errors.ReplyError: Host unreachable
should be handled properly.Actual behavior
But it causes
TypeError: ConnectionError() takes no keyword arguments
.Traceback
+------------------------------------
Telethon version
1.36.0
Python version
3.12
Operating system (including distribution name and version)
Ubuntu 22.04
Other details
No response
Checklist
pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip
and triggered the bug in the latest version.