{"record":{"id":"8cef575b4f3b7ece","repo":"AlexxIT/go2rtc","slug":"onvif-wrong-response-res-status","errorCode":null,"errorMessage":"onvif: wrong response ${res.Status}","messagePattern":"onvif: wrong response (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/onvif/client.go","lineNumber":193,"sourceCode":"}\n\nfunc (c *Client) Request(url, body string) ([]byte, error) {\n\tif url == \"\" {\n\t\treturn nil, errors.New(\"onvif: unsupported service\")\n\t}\n\n\te := NewEnvelopeWithUser(c.url.User)\n\te.Append(body)\n\n\tclient := &http.Client{Timeout: time.Second * 5000}\n\tres, err := client.Post(url, `application/soap+xml;charset=utf-8`, bytes.NewReader(e.Bytes()))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer res.Body.Close()\n\n\tif res.StatusCode != http.StatusOK {\n\t\treturn nil, errors.New(\"onvif: wrong response \" + res.Status)\n\t}\n\n\treturn io.ReadAll(res.Body)\n}\n","sourceCodeStart":175,"sourceCodeEnd":198,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/onvif/client.go#L175-L198","documentation":"Request in pkg/onvif/client.go performs the HTTP POST of the SOAP envelope to the resolved ONVIF service URL and, if the HTTP response status is anything other than 200 OK, returns errors.New(\"onvif: wrong response \"+res.Status). The res.Status text includes the numeric code and reason phrase, so this is the ONVIF device rejecting the request at the HTTP transport layer before any SOAP body parsing happens.","triggerScenarios":"Any ONVIF call (GetProfile, GetStreamUri, GetSnapshotUri, GetServiceCapabilities, DeviceRequest, etc.) against a camera that answers 401 Unauthorized (bad/missing credentials in the URL userinfo), 404 (wrong service path), 405, or 5xx (device overloaded/rebooting).","commonSituations":"Wrong username/password (or wrong digest-auth handling) in the ONVIF URL; camera firmware changing service paths; camera mid-reboot returning 503; calling an HTTPS URL on an HTTP-only port or vice versa; WS-Addressing/Action headers rejected by stricter firmwares returning 400/500.","solutions":["Check the numeric code in the message: 401 means fix credentials — pass correct username:password in the device URL userinfo and re-dial","Confirm the service URL scheme/port matches the camera (http vs https, port 80/8899/etc.) via GetCapabilities/GetServices","Retry after a delay for 5xx — cameras commonly return 503 while rebooting or under load","Capture the response body with a raw HTTP client/proxy to see whether the camera returned a SOAP fault with the status","Update camera firmware if it returns 400/500 for spec-compliant requests"],"exampleFix":"// before\nuri, err := cam.GetStreamUri(...) // \"onvif: wrong response 401 Unauthorized\"\n// after\n// ensure credentials are part of the dial URL\nu, _ := url.Parse(\"onvif://admin:correctpass@192.168.1.64:80/onvif/device_service\")\ncam, err := onvif.Dial(ctx, u)\nif err != nil { return err }\nuri, err := cam.GetStreamUri(...)","handlingStrategy":"retry","validationCode":"if u.User == nil || u.User.Username() == \"\" {\n    return errors.New(\"onvif: device URL missing credentials\")\n}","typeGuard":"func isHTTPStatusErr(err error, code string) bool {\n    return err != nil && strings.Contains(err.Error(), \"onvif: wrong response \"+code)\n}","tryCatchPattern":"var data []byte\nfor i := 0; i < 3; i++ {\n    data, err = cam.DeviceRequest(ctx, op)\n    if err == nil { break }\n    if strings.Contains(err.Error(), \"401\") {\n        return fmt.Errorf(\"onvif auth failed: check credentials in device URL\")\n    }\n    if strings.Contains(err.Error(), \"onvif: wrong response 5\") {\n        time.Sleep(time.Duration(1<<i) * time.Second)\n        continue\n    }\n    return err\n}","preventionTips":["Embed correct username:password in the ONVIF URL and rotate camera passwords centrally","Match URL scheme and port to what the camera advertises via GetCapabilities","Retry 5xx responses with exponential backoff — cameras return 503 during reboots","Test calls against the camera with a raw HTTP client to see SOAP fault bodies behind non-200 statuses"],"tags":["onvif","http","soap","camera"],"backgroundTag":"http-non-200-response","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}