mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-22 18:07:21 +00:00
Make the use of proxies an optional dependency
This commit is contained in:
parent
6aae3a9c77
commit
dd4e41f63f
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user