1

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 ...
5
  • Check server side logs. Error 503 means Service Unavailable. If it is during load - congratulations, your test has maxed out your system. If it happens even with just a single User and there is nothing in the server side logs, try to compare the exact payload sent by locust to the one sent by your browser docs.locust.io/en/stable/… Commented Nov 16 at 13:05
  • this is payload sent by browser when doing manually ------WebKitFormBoundaryqwertysss Content-Disposition: form-data; name="file"; filename="xyz.xlsx" Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ------WebKitFormBoundaryqwertysss-- Commented Nov 17 at 14:53
  • It is also interesting that if I do something manually I see response 200, but when doing the same thing with locust I see nothing in terminal Commented Nov 17 at 15:28
  • are you having this issue also whit 1 user? Also, what would you expect to have in the terminal? Commented Nov 18 at 6:50
  • I managed to solve issue. Commented 18 hours ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.