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: