From 7c29a29af1ccd3c01a6cb5dfc654b28aacc0ece0 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Tue, 12 Nov 2024 19:01:50 +0100 Subject: [PATCH] When specifying locustfile fia url, output start of response text when it wasnt valid python. --- locust/argument_parser.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/locust/argument_parser.py b/locust/argument_parser.py index 39aaf89526..5e00126fb0 100644 --- a/locust/argument_parser.py +++ b/locust/argument_parser.py @@ -162,13 +162,17 @@ def download_locustfile_from_url(url: str) -> str: """ try: response = requests.get(url) - # Check if response is valid python code - ast.parse(response.text) except requests.exceptions.RequestException as e: sys.stderr.write(f"Failed to get locustfile from: {url}. Exception: {e}") sys.exit(1) - except SyntaxError: - sys.stderr.write(f"Failed to get locustfile from: {url}. Response is not valid python code.") + else: + try: + # Check if response is valid python code + ast.parse(response.text) + except SyntaxError: + sys.stderr.write( + f"Failed to get locustfile from: {url}. Response was not valid python code: '{response.text[:100]}'" + ) sys.exit(1) with open(os.path.join(tempfile.gettempdir(), urlparse(url).path.split("/")[-1]), "w") as locustfile: