Skip to content

Commit 9e8c7c7

Browse files
authored
Merge pull request #2007 from seleniumbase/optimize-requests-timeouts
Optimize timeouts in requests
2 parents 12d9ed2 + 34a2138 commit 9e8c7c7

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

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.6"
2+
__version__ = "4.17.7"

seleniumbase/console_scripts/sb_install.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ def requests_get(url):
132132
if use_proxy:
133133
proxies = {protocol: proxy_string}
134134
try:
135-
response = requests.get(url, proxies=proxies, timeout=3)
135+
response = requests.get(url, proxies=proxies, timeout=1.25)
136136
except Exception:
137137
# Prevent SSLCertVerificationError / CERTIFICATE_VERIFY_FAILED
138138
url = url.replace("https://", "http://")
139139
time.sleep(0.04)
140-
response = requests.get(url, proxies=proxies, timeout=4)
140+
response = requests.get(url, proxies=proxies, timeout=2.75)
141141
return response
142142

143143

@@ -148,14 +148,14 @@ def requests_get_with_retry(url):
148148
if use_proxy:
149149
proxies = {protocol: proxy_string}
150150
try:
151-
response = requests.get(url, proxies=proxies, timeout=3)
151+
response = requests.get(url, proxies=proxies, timeout=1.35)
152152
except Exception:
153153
time.sleep(1)
154154
try:
155-
response = requests.get(url, proxies=proxies, timeout=4)
155+
response = requests.get(url, proxies=proxies, timeout=2.45)
156156
except Exception:
157157
time.sleep(1)
158-
response = requests.get(url, proxies=proxies, timeout=4)
158+
response = requests.get(url, proxies=proxies, timeout=3.55)
159159
return response
160160

161161

seleniumbase/core/browser_launcher.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,31 +100,23 @@ def requests_get(url, proxy_string=None):
100100
import requests
101101

102102
protocol = "http"
103+
proxies = None
103104
if proxy_string:
104105
if proxy_string.endswith(":443"):
105106
protocol = "https"
106107
elif "socks4" in proxy_string:
107108
protocol = "socks4"
108109
elif "socks5" in proxy_string:
109110
protocol = "socks5"
110-
response = None
111-
if proxy_string:
112111
proxies = {protocol: proxy_string}
113-
try:
114-
response = requests.get(url, proxies=proxies, timeout=3)
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, timeout=4)
120-
else:
121-
try:
122-
response = requests.get(url, timeout=3)
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, timeout=4)
112+
response = None
113+
try:
114+
response = requests.get(url, proxies=proxies, timeout=1.25)
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, timeout=2.75)
128120
return response
129121

130122

0 commit comments

Comments
 (0)