Skip to content

Commit a862fe7

Browse files
harshhbtharshbt
authored andcommitted
Add support for insecure/self‑signed proxy connections
- Introduce `allow_self_signed` flag in `ProxyConfig`. - Propagate flag to HTTP client (`verify=False`). - Add `--insecure-proxy` CLI option to enable the flag. - Adjust proxy handling logic accordingly.
1 parent b144075 commit a862fe7

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

youtube_transcript_api/_api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def __init__(
3737
# http_client.cookies = _load_cookie_jar(cookie_path)
3838
if proxy_config is not None:
3939
http_client.proxies = proxy_config.to_requests_dict()
40+
41+
if proxy_config.allow_self_signed:
42+
http_client.verify = False
43+
4044
if proxy_config.prevent_keeping_connections_alive:
4145
http_client.headers.update({"Connection": "close"})
4246
if proxy_config.retries_when_blocked > 0:

youtube_transcript_api/_cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def run(self) -> str:
2424
http_url=parsed_args.http_proxy,
2525
https_url=parsed_args.https_proxy,
2626
)
27-
27+
if parsed_args.insecure_proxy:
28+
proxy_config.allow_self_signed = True
2829
if (
2930
parsed_args.webshare_proxy_username is not None
3031
or parsed_args.webshare_proxy_password is not None
@@ -188,6 +189,11 @@ def _parse_args(self):
188189
metavar="URL",
189190
help="Use the specified HTTPS proxy.",
190191
)
192+
parser.add_argument(
193+
"--insecure-proxy",
194+
action="store_true",
195+
help="Allow insecure proxy connections with self-signed certificates.",
196+
)
191197
# Cookie auth has been temporarily disabled, as it is not working properly with
192198
# YouTube's most recent changes.
193199
# parser.add_argument(

youtube_transcript_api/proxies.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ class ProxyConfig(ABC):
2222
The base class for all proxy configs. Anything can be a proxy config, as longs as
2323
it can be turned into a `RequestsProxyConfigDict` by calling `to_requests_dict`.
2424
"""
25+
@property
26+
def allow_self_signed(self) -> bool:
27+
return getattr(self, "_allow_self_signed", False)
28+
29+
@allow_self_signed.setter
30+
def allow_self_signed(self, value: bool):
31+
self._allow_self_signed = bool(value)
2532

2633
@abstractmethod
2734
def to_requests_dict(self) -> RequestsProxyConfigDict:

0 commit comments

Comments
 (0)