Skip to content

Commit a37f0b2

Browse files
authored
python3Packages.youtube-search-python: patch for httpx >= 0.28 (NixOS#396845)
youtube-search-python: fix for proxies issue
1 parent b8e9b34 commit a37f0b2

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

pkgs/development/python-modules/youtube-search-python/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ buildPythonPackage rec {
1818
hash = "sha256-RWjR12ns1+tLuDZfBO7G42TF9w7sezdl9UPa67E1/PU=";
1919
};
2020

21+
patches = [ ./fix-httpx-proxies.patch ];
22+
2123
propagatedBuildInputs = [ httpx ];
2224

2325
pythonImportsCheck = [ "youtubesearchpython" ];
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--- a/youtubesearchpython/core/requests.py
2+
+++ b/youtubesearchpython/core/requests.py
3+
@@ -11,29 +11,28 @@ class RequestCore:
4+
self.proxy = {}
5+
http_proxy = os.environ.get("HTTP_PROXY")
6+
if http_proxy:
7+
- self.proxy["http://"] = http_proxy
8+
+ self.proxy["http://"] = httpx.HTTPTransport(proxy=http_proxy)
9+
https_proxy = os.environ.get("HTTPS_PROXY")
10+
if https_proxy:
11+
- self.proxy["https://"] = https_proxy
12+
+ self.proxy["https://"] = httpx.HTTPTransport(proxy=https_proxy)
13+
14+
def syncPostRequest(self) -> httpx.Response:
15+
- return httpx.post(
16+
+ return httpx.Client(mounts=self.proxy).post(
17+
self.url,
18+
headers={"User-Agent": userAgent},
19+
json=self.data,
20+
- timeout=self.timeout,
21+
- proxies=self.proxy
22+
+ timeout=self.timeout
23+
)
24+
25+
async def asyncPostRequest(self) -> httpx.Response:
26+
- async with httpx.AsyncClient(proxies=self.proxy) as client:
27+
+ async with httpx.AsyncClient(mounts=self.proxy) as client:
28+
r = await client.post(self.url, headers={"User-Agent": userAgent}, json=self.data, timeout=self.timeout)
29+
return r
30+
31+
def syncGetRequest(self) -> httpx.Response:
32+
- return httpx.get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'}, proxies=self.proxy)
33+
+ return httpx.Client(mounts=self.proxy).get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'})
34+
35+
async def asyncGetRequest(self) -> httpx.Response:
36+
- async with httpx.AsyncClient(proxies=self.proxy) as client:
37+
+ async with httpx.AsyncClient(mounts=self.proxy) as client:
38+
r = await client.get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'})
39+
return r

0 commit comments

Comments
 (0)