youtube-transcript-api icon indicating copy to clipboard operation
youtube-transcript-api copied to clipboard

Allow for specifying CA certificates (required for some HTTPS proxies #303)

Open danielsanmartin opened this issue 1 year ago • 3 comments

To fetch HTTPS pages, you will need to download and install the a certificate in your HTTP client. In this case, we need to pass to requests the verify paramenter which sets the path to certificate.

danielsanmartin avatar Aug 07 '24 14:08 danielsanmartin

very useful, @danielsanmartin - do you have some sort of a walkthrough, on how exactly I need to install those ca certificates and specify them here?

0xRaduan avatar Aug 07 '24 16:08 0xRaduan

Also, it would be great if you could mention this param in the README. I think you can just add it to the Proxy section.

jdepoix avatar Aug 08 '24 09:08 jdepoix

Hi. I already did the requested changes.

danielsanmartin avatar Aug 10 '24 23:08 danielsanmartin

Hi @danielsanmartin!

sorry that it took so long, but I was hesitant about merging this, as I had some larger-scale changes to the API in mind, which I just got around to releasing in v1.0.0!

In this new version an instance of YouTubeTranscriptApi can be initialized with a requests.Session object. This allows for specifying the CA bundle file, but at the same time allows for doing other things like settings custom headers!

from requests import Session

http_client = Session()

# set custom header
http_client.headers.update({"Accept-Encoding": "gzip, deflate"})

# set path to CA_BUNDLE file
http_client.verify = "/path/to/certfile"

ytt_api = YouTubeTranscriptApi(http_client=session)
ytt_api.fetch(video_id)

# share same Session between two instances of YouTubeTranscriptApi
ytt_api_2 = YouTubeTranscriptApi(http_client=session)
# now shares cookies with ytt_api
ytt_api_2.fetch(video_id)

Since this new API allows for setting CA bundles without requiring an extra param for it, I will close this PR now. Nonetheless, thank you very much for your contribution @danielsanmartin! 😊🙏

jdepoix avatar Mar 11 '25 19:03 jdepoix