Skip to content

Commit

Permalink
fix: add timeout to get_url http request
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquimds committed Oct 3, 2024
1 parent d50d5e5 commit 43ab4e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion wagtaillinkchecker/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_url(url, page, site):
}
response = None
try:
response = requests.get(url, verify=True)
response = requests.get(url, verify=True, timeout=30)
data["response"] = response
except (requests.exceptions.InvalidSchema, requests.exceptions.MissingSchema):
data["invalid_schema"] = True
Expand Down
4 changes: 4 additions & 0 deletions wagtaillinkchecker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ def check_link(
def check_link_sync(link_pk, verbosity=1):
link = ScanLink.objects.get(pk=link_pk)
site = link.scan.site
if verbosity > 1:
print(f"Checking {link.url}")
url = get_url(link.url, link.page, site)
link.status_code = url.get("status_code")
if verbosity > 1:
print(f"Link is {'broken' if url['error'] else 'OK'}")

if url["error"]:
link.broken = True
Expand Down

0 comments on commit 43ab4e3

Please sign in to comment.