-
-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Yewtube needs httpx less than 0.28 #396811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hello, Thanks for your PR, but I can't help but think that this kind of issue should be fixed upstream, not downstream. Perhaps I'm wrong here, but it feels weird to do that to fix something that should be fixed upstream. |
I agree, currently the issue was closed on yewtube side, I was planning to ask for reopening it. But in the meantime, as there is a workaround, don't you think that it would be beneficial for all other nixpkgs users to at least have the opportunity to use yewtube? |
This is currently necessary to work around the following yewtube issue: mps-youtube/yewtube#1303
7bd7749 to
6a43d37
Compare
|
Would be better to fix the root cause here: https://github.com/alexmercerind/youtube-search-python/blob/main/youtubesearchpython/core/requests.py#L25 Using the patch below. Code adapted using information from encode/httpx#2879 diff --git a/youtubesearchpython/core/requests.py b/youtubesearchpython/core/requests.py
index ea3ed7f..3eaa2a3 100644
--- a/youtubesearchpython/core/requests.py
+++ b/youtubesearchpython/core/requests.py
@@ -11,10 +11,10 @@ class RequestCore:
self.proxy = {}
http_proxy = os.environ.get("HTTP_PROXY")
if http_proxy:
- self.proxy["http://"] = http_proxy
+ self.proxy["http://"] = httpx.HTTPTransport(proxy=http_proxy)
https_proxy = os.environ.get("HTTPS_PROXY")
if https_proxy:
- self.proxy["https://"] = https_proxy
+ self.proxy["https://"] = httpx.HTTPTransport(proxy=https_proxy)
def syncPostRequest(self) -> httpx.Response:
return httpx.post(
@@ -22,18 +22,18 @@ class RequestCore:
headers={"User-Agent": userAgent},
json=self.data,
timeout=self.timeout,
- proxies=self.proxy
+ mounts=self.proxy
)
async def asyncPostRequest(self) -> httpx.Response:
- async with httpx.AsyncClient(proxies=self.proxy) as client:
+ async with httpx.AsyncClient(mounts=self.proxy) as client:
r = await client.post(self.url, headers={"User-Agent": userAgent}, json=self.data, timeout=self.timeout)
return r
def syncGetRequest(self) -> httpx.Response:
- return httpx.get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'}, proxies=self.proxy)
+ return httpx.get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'}, mounts=self.proxy)
async def asyncGetRequest(self) -> httpx.Response:
- async with httpx.AsyncClient(proxies=self.proxy) as client:
+ async with httpx.AsyncClient(mounts=self.proxy) as client:
r = await client.get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'})
return rSave as |
|
Note: the patch above cannot be upstreamed, since the corresponding repository is archived. |
|
I definitely prefer the solution proposed by @FliegendeWurst ! (CC @amozeo) |
Ok, that explains why the current fix proposed on In the meantime (and it will probably take long on |
Yes, this will benefit other users of the package too. Save the patch in |
Ok, I'll create a new PR for this and will close this one when the new one is ready. |
|
You can do everything within this PR. |
|
I don't use yewtube package myself. I like the proposed solution of patching |
@drupol I just saw your message, I have already started a new branch, my apologies. Seems like the patch for post() got an unexpected keyword argument 'mounts'I am looking into it. |
|
It seems the right patch would be: --- a/youtubesearchpython/core/requests.py
+++ b/youtubesearchpython/core/requests.py
@@ -11,10 +11,10 @@ class RequestCore:
self.proxy = {}
http_proxy = os.environ.get("HTTP_PROXY")
if http_proxy:
- self.proxy["http://"] = http_proxy
+ self.proxy["http://"] = httpx.HTTPTransport(proxy=http_proxy)
https_proxy = os.environ.get("HTTPS_PROXY")
if https_proxy:
- self.proxy["https://"] = https_proxy
+ self.proxy["https://"] = httpx.HTTPTransport(proxy=https_proxy)
def syncPostRequest(self) -> httpx.Response:
return httpx.post(
@@ -22,18 +22,17 @@ class RequestCore:
headers={"User-Agent": userAgent},
json=self.data,
timeout=self.timeout,
- proxies=self.proxy
)
async def asyncPostRequest(self) -> httpx.Response:
- async with httpx.AsyncClient(proxies=self.proxy) as client:
+ async with httpx.AsyncClient(mounts=self.proxy) as client:
r = await client.post(self.url, headers={"User-Agent": userAgent}, json=self.data, timeout=self.timeout)
return r
def syncGetRequest(self) -> httpx.Response:
- return httpx.get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'}, proxies=self.proxy)
+ return httpx.get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'}, mounts=self.proxy)
async def asyncGetRequest(self) -> httpx.Response:
- async with httpx.AsyncClient(proxies=self.proxy) as client:
+ async with httpx.AsyncClient(mounts=self.proxy) as client:
r = await client.get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'})
return r
|
|
I think |
|
Though it may be safer to just remove the proxies argument, yes. Certainly easier to test. |
|
And I took the time to read the --- a/youtubesearchpython/core/requests.py
+++ b/youtubesearchpython/core/requests.py
@@ -11,29 +11,28 @@ class RequestCore:
self.proxy = {}
http_proxy = os.environ.get("HTTP_PROXY")
if http_proxy:
- self.proxy["http://"] = http_proxy
+ self.proxy["http://"] = httpx.HTTPTransport(proxy=http_proxy)
https_proxy = os.environ.get("HTTPS_PROXY")
if https_proxy:
- self.proxy["https://"] = https_proxy
+ self.proxy["https://"] = httpx.HTTPTransport(proxy=https_proxy)
def syncPostRequest(self) -> httpx.Response:
- return httpx.post(
+ return httpx.Client(mounts=self.proxy).post(
self.url,
headers={"User-Agent": userAgent},
json=self.data,
- timeout=self.timeout,
- proxies=self.proxy
+ timeout=self.timeout
)
async def asyncPostRequest(self) -> httpx.Response:
- async with httpx.AsyncClient(proxies=self.proxy) as client:
+ async with httpx.AsyncClient(mounts=self.proxy) as client:
r = await client.post(self.url, headers={"User-Agent": userAgent}, json=self.data, timeout=self.timeout)
return r
def syncGetRequest(self) -> httpx.Response:
- return httpx.get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'}, proxies=self.proxy)
+ return httpx.Client(mounts=self.proxy).get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'})
async def asyncGetRequest(self) -> httpx.Response:
- async with httpx.AsyncClient(proxies=self.proxy) as client:
+ async with httpx.AsyncClient(mounts=self.proxy) as client:
r = await client.get(self.url, headers={"User-Agent": userAgent}, timeout=self.timeout, cookies={'CONSENT': 'YES+1'})
return rI should have started with this in the first place 🤣. |
|
The new pull request is available, see #396845. |
Hello,
Currently
yewtubedoes not supporthttpx>=0.28.0, see:#394572
These changes ensure that
http=0.27.2is used in order to work around this issue.I am new to Python packages overriding, so if I am doing it wrong, please advise.
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.