Skip to content

Commit 71d0b84

Browse files
authored
Merge pull request #566 from cjkangme/master
fix: prevent duplicate -rotate suffix in proxy username
2 parents 9f270da + 8342000 commit 71d0b84

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

youtube_transcript_api/proxies.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ def url(self) -> str:
160160
location_codes = "".join(
161161
f"-{location_code.upper()}" for location_code in self._filter_ip_locations
162162
)
163+
username = self.proxy_username
164+
suffix = "-rotate"
165+
if username.endswith(suffix):
166+
username = username[: -len(suffix)]
163167
return (
164-
f"http://{self.proxy_username}{location_codes}-rotate:{self.proxy_password}"
168+
f"http://{username}{location_codes}{suffix}:{self.proxy_password}"
165169
f"@{self.domain_name}:{self.proxy_port}/"
166170
)
167171

youtube_transcript_api/test/test_proxies.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,15 @@ def test_to_requests_dict__with_multiple_location_filters(self):
9191
"http": "http://user-DE-US-rotate:password@p.webshare.io:80/",
9292
"https": "http://user-DE-US-rotate:password@p.webshare.io:80/",
9393
}
94+
95+
def test_to_requests_dict__with_rotate_suffix_in_username(self):
96+
proxy_config = WebshareProxyConfig(
97+
proxy_username="user-rotate", proxy_password="password"
98+
)
99+
100+
request_dict = proxy_config.to_requests_dict()
101+
102+
assert request_dict == {
103+
"http": "http://user-rotate:password@p.webshare.io:80/",
104+
"https": "http://user-rotate:password@p.webshare.io:80/",
105+
}

0 commit comments

Comments
 (0)