Skip to content

Commit 3d22534

Browse files
authored
Merge pull request #1997 from seleniumbase/fix-issue-with-proxies-in-uc-mode
Fix issue with proxies in UC Mode
2 parents 2ccb7b5 + a814340 commit 3d22534

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

mkdocs_build/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pipdeptree>=2.12.0
1111
bleach>=6.0.0
1212
docutils>=0.20.1
1313
python-dateutil>=2.8.2
14-
tqdm>=4.66.0
14+
tqdm>=4.66.1
1515
nltk>=3.8.1
1616
joblib>=1.3.2
1717
livereload==2.6.3
@@ -21,7 +21,7 @@ Jinja2==3.1.2
2121
click==8.1.6
2222
ghp-import==2.1.0
2323
lunr==0.6.2
24-
tornado==6.3.2
24+
tornado==6.3.3
2525
watchdog==3.0.0
2626
cairocffi==1.6.1
2727
cairosvg==2.7.1

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pygments==2.14.0;python_version<"3.7"
7070
pygments==2.16.1;python_version>="3.7"
7171
pyreadline3==3.4.1;platform_system=="Windows"
7272
tabcompleter==1.2.1
73-
pdbp==1.4.4
73+
pdbp==1.4.5
7474
colorama==0.4.5;python_version<"3.7"
7575
colorama==0.4.6;python_version>="3.7"
7676
exceptiongroup==1.1.2;python_version>="3.7"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.17.2"
2+
__version__ = "4.17.3"

seleniumbase/core/browser_launcher.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,35 @@ def make_driver_executable_if_not(driver_path):
9696
make_executable(driver_path)
9797

9898

99-
def requests_get(url):
99+
def requests_get(url, proxy_string=None):
100100
import requests
101101

102+
protocol = "http"
103+
if proxy_string:
104+
if proxy_string.endswith(":443"):
105+
protocol = "https"
106+
elif "socks4" in proxy_string:
107+
protocol = "socks4"
108+
elif "socks5" in proxy_string:
109+
protocol = "socks5"
102110
response = None
103-
try:
104-
response = requests.get(url)
105-
except Exception:
106-
# Prevent SSLCertVerificationError / CERTIFICATE_VERIFY_FAILED
107-
url = url.replace("https://", "http://")
108-
response = requests.get(url)
111+
if proxy_string:
112+
proxies = {protocol: proxy_string}
113+
try:
114+
response = requests.get(url, proxies=proxies)
115+
except Exception:
116+
# Prevent SSLCertVerificationError / CERTIFICATE_VERIFY_FAILED
117+
url = url.replace("https://", "http://")
118+
time.sleep(0.04)
119+
response = requests.get(url, proxies=proxies)
120+
else:
121+
try:
122+
response = requests.get(url)
123+
except Exception:
124+
# Prevent SSLCertVerificationError / CERTIFICATE_VERIFY_FAILED
125+
url = url.replace("https://", "http://")
126+
time.sleep(0.04)
127+
response = requests.get(url)
109128
return response
110129

111130

@@ -178,6 +197,7 @@ def find_edgedriver_version_to_use(use_version, driver_version):
178197
def has_cf(text):
179198
if (
180199
"<title>Just a moment...</title>" in text
200+
or "<title>403 Forbidden</title>" in text
181201
or 'id="challenge-error-text"' in text
182202
or 'action="/?__cf_chl_f_tk' in text
183203
or 'id="challenge-form"' in text
@@ -187,10 +207,10 @@ def has_cf(text):
187207
return False
188208

189209

190-
def uc_special_open_if_cf(driver, url):
210+
def uc_special_open_if_cf(driver, url, proxy_string=None):
191211
if (
192212
(url.startswith("http:") or url.startswith("https:"))
193-
and has_cf(requests_get(url).text)
213+
and has_cf(requests_get(url, proxy_string).text)
194214
):
195215
with driver:
196216
time.sleep(0.25)
@@ -3405,7 +3425,9 @@ def get_local_driver(
34053425
)
34063426
driver.open = driver.get # Save copy of original
34073427
if uc_activated:
3408-
driver.get = lambda url: uc_special_open_if_cf(driver, url)
3428+
driver.get = lambda url: uc_special_open_if_cf(
3429+
driver, url, proxy_string
3430+
)
34093431
driver.uc_open = lambda url: uc_open(driver, url)
34103432
driver.uc_open_with_tab = (
34113433
lambda url: uc_open_with_tab(driver, url)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
'pygments==2.16.1;python_version>="3.7"',
205205
'pyreadline3==3.4.1;platform_system=="Windows"',
206206
"tabcompleter==1.2.1",
207-
"pdbp==1.4.4",
207+
"pdbp==1.4.5",
208208
'colorama==0.4.5;python_version<"3.7"',
209209
'colorama==0.4.6;python_version>="3.7"',
210210
'exceptiongroup==1.1.2;python_version>="3.7"',

0 commit comments

Comments
 (0)