From 7e346180d781f346c842c6acd811a05f3dc2b8c9 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 31 Oct 2019 19:20:18 +0100 Subject: [PATCH] Fix import ssl may fail under some Python installs It's only required for certain proxy configurations, so we don't want it to raise ImportError while the user imports our library. --- telethon/network/connection/connection.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/telethon/network/connection/connection.py b/telethon/network/connection/connection.py index f38f4be3..27869eda 100644 --- a/telethon/network/connection/connection.py +++ b/telethon/network/connection/connection.py @@ -1,9 +1,13 @@ import abc import asyncio import socket -import ssl as ssl_mod import sys +try: + import ssl as ssl_mod +except ImportError: + ssl_mod = None + from ...errors import InvalidChecksumError from ... import helpers @@ -68,6 +72,12 @@ class Connection(abc.ABC): loop=self._loop ) if ssl: + if ssl_mod is None: + raise RuntimeError( + 'Cannot use proxy that requires SSL' + 'without the SSL module being available' + ) + s.settimeout(timeout) s = ssl_mod.wrap_socket( s,