at master 1.9 kB view raw
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