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)