[GH-ISSUE #104] DeleteVm silently ignores a 501 response #17

Closed
opened 2026-02-28 00:40:12 +03:00 by kerem · 1 comment
Owner

Originally created by @ghost on GitHub (Mar 4, 2021).
Original GitHub issue: https://github.com/Telmate/proxmox-api-go/issues/104

When I call DeleteVm, it calls DeleteVmParams, which seems to ignore an error returned by the server.
After turning debug on, I get the following:

Request:

DELETE /api2/json/nodes/vme/qemu/105 HTTP/1.1
Host: vme.test:8006
User-Agent: Go-http-client/1.1
Content-Length: 2
Accept: application/json
Cookie: PVEAuthCookie=...
Csrfpreventiontoken: ...
Accept-Encoding: gzip

""

Response:

HTTP/1.1 501 Unexpected content for method 'DELETE'
Connection: close
Cache-Control: max-age=0
Date: Thu, 04 Mar 2021 19:02:38 GMT
Expires: Thu, 04 Mar 2021 19:02:38 GMT
Pragma: no-cache
Server: pve-api-daemon/3.0

However, as a caller, I get err = nil in the result of the call to DeleteVm


When I call the endpoint manually:

curl \
  -H 'Accept: application/json' \
  -H 'Cookie: PVEAuthCookie=...' \
  -H 'Csrfpreventiontoken: ...' \
  -X DELETE https://vme.test:8006/api2/json/nodes/vme/qemu/105 \
  -d '' \
  --verbose -k

it works fine and proxmox removes the VM.


This happens on 7008020 and Proxmox version: 6.3-4 (I also observed it on 6.2-11)

Originally created by @ghost on GitHub (Mar 4, 2021). Original GitHub issue: https://github.com/Telmate/proxmox-api-go/issues/104 When I call `DeleteVm`, it calls `DeleteVmParams`, which seems to ignore an error returned by the server. After turning debug on, I get the following: Request: ```http DELETE /api2/json/nodes/vme/qemu/105 HTTP/1.1 Host: vme.test:8006 User-Agent: Go-http-client/1.1 Content-Length: 2 Accept: application/json Cookie: PVEAuthCookie=... Csrfpreventiontoken: ... Accept-Encoding: gzip "" ``` Response: ```http HTTP/1.1 501 Unexpected content for method 'DELETE' Connection: close Cache-Control: max-age=0 Date: Thu, 04 Mar 2021 19:02:38 GMT Expires: Thu, 04 Mar 2021 19:02:38 GMT Pragma: no-cache Server: pve-api-daemon/3.0 ``` However, as a caller, I get `err = nil` in the result of the call to `DeleteVm` ---- When I call the endpoint manually: ```sh curl \ -H 'Accept: application/json' \ -H 'Cookie: PVEAuthCookie=...' \ -H 'Csrfpreventiontoken: ...' \ -X DELETE https://vme.test:8006/api2/json/nodes/vme/qemu/105 \ -d '' \ --verbose -k ``` it works fine and proxmox removes the VM. ---- This happens on 7008020 and Proxmox version: 6.3-4 (I also observed it on 6.2-11)
kerem closed this issue 2026-02-28 00:40:12 +03:00
Author
Owner

@GmzAmz commented on GitHub (May 3, 2021):

Disclaimer: I barely know go. I am 100% sure there's a better way to do this.

I have this issue as well. You can recreate the problem by passing '""' to -d in curl in your manual example. Appears as if it's expecting a body but it doesn't have one. Since it passes it passes an empty map rather than nil, it runs jsonMarshal on nothing, producing "". That's what's causing the error.

I was able to fix it by checking len(reqbody) and if it's 0, passing nil to RequestJSON rather than &reqbody. No guarantees that doesn't mess up something else, though the only function that references this function is just a thin wrapper so it might be fine.

diff --git a/proxmox/client.go b/proxmox/client.go
index ee4acf3..761e1af 100644
--- a/proxmox/client.go
+++ b/proxmox/client.go
@@ -493,7 +493,11 @@ func (c *Client) DeleteVmParams(vmr *VmRef, params map[string]interface{}) (exit
        reqbody := ParamsToBody(params)
        url := fmt.Sprintf("/nodes/%s/%s/%d", vmr.node, vmr.vmType, vmr.vmId)
        var taskResponse map[string]interface{}
-       _, err = c.session.RequestJSON("DELETE", url, nil, nil, &reqbody, &taskResponse)
+  if len(reqbody) != 0 {
+         _, err = c.session.RequestJSON("DELETE", url, nil, nil, &reqbody, &taskResponse)
+  } else {
+    _, err = c.session.RequestJSON("DELETE", url, nil, nil, nil, &taskResponse)
+  }
        exitStatus, err = c.WaitForCompletion(taskResponse)
        return
 }
<!-- gh-comment-id:830997467 --> @GmzAmz commented on GitHub (May 3, 2021): Disclaimer: I barely know go. I am 100% sure there's a better way to do this. I have this issue as well. You can recreate the problem by passing `'""'` to -d in curl in your manual example. Appears as if it's expecting a body but it doesn't have one. Since it passes it passes an empty map rather than nil, it runs jsonMarshal on nothing, producing `""`. That's what's causing the error. I was able to fix it by checking len(reqbody) and if it's 0, passing nil to RequestJSON rather than &reqbody. No guarantees that doesn't mess up something else, though the only function that references this function is just a thin wrapper so it _might_ be fine. ```diff diff --git a/proxmox/client.go b/proxmox/client.go index ee4acf3..761e1af 100644 --- a/proxmox/client.go +++ b/proxmox/client.go @@ -493,7 +493,11 @@ func (c *Client) DeleteVmParams(vmr *VmRef, params map[string]interface{}) (exit reqbody := ParamsToBody(params) url := fmt.Sprintf("/nodes/%s/%s/%d", vmr.node, vmr.vmType, vmr.vmId) var taskResponse map[string]interface{} - _, err = c.session.RequestJSON("DELETE", url, nil, nil, &reqbody, &taskResponse) + if len(reqbody) != 0 { + _, err = c.session.RequestJSON("DELETE", url, nil, nil, &reqbody, &taskResponse) + } else { + _, err = c.session.RequestJSON("DELETE", url, nil, nil, nil, &taskResponse) + } exitStatus, err = c.WaitForCompletion(taskResponse) return } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/proxmox-api-go#17
No description provided.