Skip to content

Commit afcc63b

Browse files
committed
Add "timeout" to "requests.get()" calls
1 parent 89de9e8 commit afcc63b

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,20 @@ def requests_get(url, proxy_string=None):
111111
if proxy_string:
112112
proxies = {protocol: proxy_string}
113113
try:
114-
response = requests.get(url, proxies=proxies)
114+
response = requests.get(url, proxies=proxies, timeout=3)
115115
except Exception:
116116
# Prevent SSLCertVerificationError / CERTIFICATE_VERIFY_FAILED
117117
url = url.replace("https://", "http://")
118118
time.sleep(0.04)
119-
response = requests.get(url, proxies=proxies)
119+
response = requests.get(url, proxies=proxies, timeout=4)
120120
else:
121121
try:
122-
response = requests.get(url)
122+
response = requests.get(url, timeout=3)
123123
except Exception:
124124
# Prevent SSLCertVerificationError / CERTIFICATE_VERIFY_FAILED
125125
url = url.replace("https://", "http://")
126126
time.sleep(0.04)
127-
response = requests.get(url)
127+
response = requests.get(url, timeout=4)
128128
return response
129129

130130

seleniumbase/fixtures/js_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def add_css_style(driver, css_style):
531531
def add_js_code_from_link(driver, js_link):
532532
if js_link.startswith("//"):
533533
js_link = "http:" + js_link
534-
js_code = requests.get(js_link).text
534+
js_code = requests.get(js_link, timeout=5).text
535535
add_js_code_script = (
536536
"""var body_tag=document.getElementsByTagName('body').item(0);"""
537537
"""var script_tag=document.createElement("script");"""

seleniumbase/fixtures/page_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def _download_file_to(file_url, destination_folder, new_file_name=None):
245245
file_name = new_file_name
246246
else:
247247
file_name = file_url.split("/")[-1]
248-
r = requests.get(file_url)
248+
r = requests.get(file_url, timeout=5)
249249
file_path = os.path.join(destination_folder, file_name)
250250
download_file_lock = fasteners.InterProcessLock(
251251
constants.MultiBrowser.DOWNLOAD_FILE_LOCK

seleniumbase/undetected/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def __init__(
143143

144144
special_port_free = False # If the port isn't free, don't use 9222
145145
try:
146-
res = requests.get("http://127.0.0.1:9222")
146+
res = requests.get("http://127.0.0.1:9222", timeout=1)
147147
if res.status_code != 200:
148148
raise Exception("The port is free! It will be used!")
149149
except Exception:

0 commit comments

Comments
 (0)