I am testing my Python Flask app using Locust to load-test a POST request with an .xlsx file attachment. However, I consistently encounter a 503 Service Unavailable error.
This issue ONLY occurs when I use Locust. When I manually test the same API it works fine.
Locust file
@task
def upload_statics_file(self):
file_path = "some_file_path.xlsx"
try:
with open(file_path, "rb") as file_to_upload:
files = {'file': file_to_upload}
print("Starting file upload test...")
with self.client.post("/api/statics_file_upload", files=files, catch_response=True) as response:
print(f"Request made to: /api/statics_file_upload")
print(f"Response Status Code: {response.status_code}") # Log status code
print(f"Response Headers: {response.headers}") # Log headers
try:
response_data = response.json() # Parse JSON
print(f"Response JSON: {response_data}")
except Exception as e:
print(f"Failed to parse response as JSON. Response Text: {response.text}")
if response.status_code == 200:
response.success()
print("File uploaded successfully!")
else:
response_text = response.text or "No response body received (empty response)"
print(f"Failed to upload file: {response_text}")
response.failure(
f"Failed to upload file. Status code: {response.status_code}, Response: {response_text}"
)
except FileNotFoundError:
print(f"File not found at: {file_path}")
The Problem
Whenever I run my Locust test, I get the following:
Starting file upload test...
Request made to: /api/statics_file_upload
Response Status Code: 503
Response Headers: {'Content-Length': '0', 'Date': 'Sun, 16 Nov 2025 12:23:31 GMT', 'Connection': 'close'}
Failed to parse response as JSON. Response Text:
Failed to upload file: No response body received (empty response)
Tried following fixes
ChatGPT suggested that issue is my url, but it is not true.
The double slash and invalid url is not a thing.
Also tried dropping @requiresauth decorator but also did not help.
Host URL(google workstation url): https://3000-abcdef-xyz-abc.cluster-xyz.cloudworkstations.dev
Endpoint code:
@upload_routes.route("/api/statics_file_upload", methods=["POST"], endpoint="upload_statics_file")
@requires_auth
def upload_statics_file():
file = request.files.get("file")
#further logic ...