Skip to content

Commit f03c595

Browse files
committed
Use requests.head() over requests.get() when possible
1 parent 08ea4f7 commit f03c595

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4756,7 +4756,7 @@ def get_link_status_code(
47564756
):
47574757
"""Get the status code of a link.
47584758
If the timeout is set to less than 1, it becomes 1.
4759-
If the timeout is exceeded by requests.get(), it will return a 404.
4759+
If the timeout is exceeded by requests.head(), it will return a 404.
47604760
If "verify" is False, will ignore certificate errors.
47614761
For a list of available status codes, see:
47624762
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
@@ -4794,6 +4794,8 @@ def assert_no_404_errors(self, multithreaded=True, timeout=None):
47944794
"""Assert no 404 errors from page links obtained from:
47954795
"a"->"href", "img"->"src", "link"->"href", and "script"->"src".
47964796
Timeout is on a per-link basis using the "requests" library.
4797+
If timeout is None, uses the one set in get_link_status_code().
4798+
(That timeout value is currently set to 5 seconds per link.)
47974799
(A 404 error represents a broken link on a web page.)
47984800
"""
47994801
all_links = self.get_unique_links()
@@ -4830,7 +4832,7 @@ def assert_no_404_errors(self, multithreaded=True, timeout=None):
48304832
for link in links:
48314833
if self.__get_link_if_404_error(link):
48324834
broken_links.append(link)
4833-
self.__requests_timeout = None # Reset the requests.get() timeout
4835+
self.__requests_timeout = None # Reset the requests.head() timeout
48344836
if len(broken_links) > 0:
48354837
broken_links = sorted(broken_links)
48364838
bad_links_str = "\n".join(broken_links)

seleniumbase/fixtures/page_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _get_link_status_code(
229229
"""
230230
status_code = None
231231
try:
232-
response = requests.get(
232+
response = requests.head(
233233
link,
234234
allow_redirects=allow_redirects,
235235
timeout=timeout,

0 commit comments

Comments
 (0)