{"record":{"id":"a4ce4f1490e3b506","repo":"trailofbits/algo","slug":"error-while-stopping-server-response-status-code","errorCode":null,"errorMessage":"Error while stopping server [{response.status_code}: {response.json}]","messagePattern":"Error while stopping server \\[(.+?): (.+?)\\]","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"library/scaleway_compute.py","lineNumber":471,"sourceCode":"        )\n\n    wait_to_complete_state_transition(compute_api=compute_api, server=target_server)\n\n    current_state = fetch_state(compute_api=compute_api, server=target_server)\n    if current_state not in (\"stopped\",):\n        compute_api.module.debug(\"stop_strategy: Server in state: %s\" % current_state)\n\n        changed = True\n\n        if compute_api.module.check_mode:\n            return changed, {\"status\": \"Server %s would be stopped.\" % target_server[\"id\"]}\n\n        response = stop_server(compute_api=compute_api, server=target_server)\n        compute_api.module.debug(response.json)\n        compute_api.module.debug(response.ok)\n\n        if not response.ok:\n            msg = f\"Error while stopping server [{response.status_code}: {response.json}]\"\n            compute_api.module.fail_json(msg=msg)\n\n    return changed, target_server\n\n\ndef restart_strategy(compute_api, wished_server):\n    compute_api.module.debug(\"Starting restart strategy\")\n    changed = False\n    query_results = find(compute_api=compute_api, wished_server=wished_server, per_page=1)\n\n    if not query_results:\n        changed = True\n        if compute_api.module.check_mode:\n            return changed, {\"status\": \"A server would be created before being rebooted.\"}\n\n        target_server = create_server(compute_api=compute_api, server=wished_server)\n    else:\n        target_server = query_results[0]","sourceCodeStart":453,"sourceCodeEnd":489,"githubUrl":"https://github.com/trailofbits/algo/blob/20e22a8715c198b38c01c1ca62d0953b93587a74/library/scaleway_compute.py#L453-L489","documentation":"This error is raised by the Scaleway compute Ansible module when the HTTP PATCH/POST request to stop (power off) a Scaleway server returns a non-2xx response. The message interpolates the HTTP status code and the parsed JSON body from the Scaleway API so the underlying cause (auth failure, wrong server state, quota, etc.) is embedded in the message.","triggerScenarios":"Calling the module with state=stopped (stop_strategy) when the Scaleway API 'poweroff' action endpoint returns an error, e.g. 401 invalid token, 404 server UUID not found, or the server is in a transient state that cannot be stopped.","commonSituations":"Expired or wrong SCW_TOKEN organization token, stale server ID from a previously deleted instance, API rate limiting, or stopping a server already in 'stopping' state.","solutions":["Check the embedded status code and response.json body in the message — it names the exact API failure","Verify the Scaleway auth token (SCW_TOKEN) and that it has Compute instance permissions","Confirm the server name resolves to an existing instance in the configured region/organization","Retry after the server finishes any in-progress state transition (wait a few seconds)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"# In Ansible: use failed_when/retries on the task\n- block:\n  - name: Stop server\n    scaleway_compute:\n      state: stopped\n      name: \"{{ server_name }}\"\n    register: stop_res\n    retries: 3\n    delay: 10\n  rescue:\n  - debug: var=stop_res","preventionTips":["Use retries/delay on Scaleway state-change tasks to absorb transient API failures","Pre-validate the auth token with a simple API call before running the play"],"tags":["scaleway","api-error","ansible","http"],"backgroundTag":"cloud-api-request-failed","analyzedSha":"20e22a8715c198b38c01c1ca62d0953b93587a74","analyzedAt":"2026-08-28T13:26:02.752Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}