2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-23 10:28:00 +00:00

Make the use of proxies an optional dependency

This commit is contained in:
Dan 2022-12-26 16:28:06 +01:00
parent 6aae3a9c77
commit dd4e41f63f

View File

@ -20,18 +20,11 @@ import asyncio
import ipaddress import ipaddress
import logging import logging
import socket import socket
import time
from typing import Optional
try: try:
import socks import socks
except ImportError as e: except ImportError:
e.msg = ( socks = None
"PySocks is missing and Pyrogram can't run without. "
"Please install it using \"pip3 install pysocks\"."
)
raise e
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -50,7 +43,10 @@ class TCP:
self.loop = asyncio.get_event_loop() self.loop = asyncio.get_event_loop()
if proxy: if proxy and not socks:
log.warning("Can't use proxy because pysocks is not installed")
if proxy and socks:
hostname = proxy.get("hostname") hostname = proxy.get("hostname")
try: try:
@ -71,7 +67,7 @@ class TCP:
password=proxy.get("password", None) password=proxy.get("password", None)
) )
log.info(f"Using proxy {hostname}") log.info("Using proxy %s", hostname)
else: else:
self.socket = socket.socket( self.socket = socket.socket(
socket.AF_INET6 if ipv6 socket.AF_INET6 if ipv6