Skip to content

Commit

Permalink
When specifying locustfile fia url, output start of response text whe…
Browse files Browse the repository at this point in the history
…n it wasnt valid python.
  • Loading branch information
cyberw committed Nov 12, 2024
1 parent 96230d9 commit 7c29a29
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions locust/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7c29a29

Please sign in to comment.