Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions youtube_transcript_api/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def __init__(
# http_client.cookies = _load_cookie_jar(cookie_path)
if proxy_config is not None:
http_client.proxies = proxy_config.to_requests_dict()

if proxy_config.allow_self_signed:
http_client.verify = False

if proxy_config.prevent_keeping_connections_alive:
http_client.headers.update({"Connection": "close"})
if proxy_config.retries_when_blocked > 0:
Expand Down
8 changes: 7 additions & 1 deletion youtube_transcript_api/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def run(self) -> str:
http_url=parsed_args.http_proxy,
https_url=parsed_args.https_proxy,
)

if parsed_args.insecure_proxy:
proxy_config.allow_self_signed = True
if (
parsed_args.webshare_proxy_username is not None
or parsed_args.webshare_proxy_password is not None
Expand Down Expand Up @@ -188,6 +189,11 @@ def _parse_args(self):
metavar="URL",
help="Use the specified HTTPS proxy.",
)
parser.add_argument(
"--insecure-proxy",
action="store_true",
help="Allow insecure proxy connections with self-signed certificates.",
)
# Cookie auth has been temporarily disabled, as it is not working properly with
# YouTube's most recent changes.
# parser.add_argument(
Expand Down
7 changes: 7 additions & 0 deletions youtube_transcript_api/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class ProxyConfig(ABC):
The base class for all proxy configs. Anything can be a proxy config, as longs as
it can be turned into a `RequestsProxyConfigDict` by calling `to_requests_dict`.
"""
@property
def allow_self_signed(self) -> bool:
return getattr(self, "_allow_self_signed", False)

@allow_self_signed.setter
def allow_self_signed(self, value: bool):
self._allow_self_signed = bool(value)

@abstractmethod
def to_requests_dict(self) -> RequestsProxyConfigDict:
Expand Down
Loading