From 4ddbc78699700796ba9013cd2841461e0f28883b Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 16 Nov 2017 13:47:15 +0100 Subject: [PATCH] Ensure IPv6 addresses are surrounded by '[]' (#425) --- telethon/extensions/tcp_client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telethon/extensions/tcp_client.py b/telethon/extensions/tcp_client.py index 164429f3..af9bfbfe 100644 --- a/telethon/extensions/tcp_client.py +++ b/telethon/extensions/tcp_client.py @@ -37,6 +37,12 @@ class TcpClient: 'timeout' must be given in seconds """ if ':' in ip: # IPv6 + # The address needs to be surrounded by [] as discussed on PR#425 + if not ip.startswith('['): + ip = '[' + ip + if not ip.endswith(']'): + ip = ip + ']' + mode, address = socket.AF_INET6, (ip, port, 0, 0) else: mode, address = socket.AF_INET, (ip, port)