{"record":{"id":"bbb688ab2b39b321","repo":"Sonarr/Sonarr","slug":"failed-to-connect-to-qbittorrent-please-check-you-bbb688","errorCode":null,"errorMessage":"Failed to connect to qBittorrent, please check your settings.","messagePattern":"Failed to connect to qBittorrent, please check your settings\\.","errorType":"exception","errorClass":"DownloadClientException","httpStatus":null,"severity":"error","filePath":"src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs","lineNumber":402,"sourceCode":"\n                try\n                {\n                    return _httpClient.Execute(requestWithApiKey).Content;\n                }\n                catch (HttpException ex)\n                {\n                    if (ex.Response.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden)\n                    {\n                        _logger.Debug(ex, \"qbitTorrent authentication failed.\");\n\n                        throw new DownloadClientAuthenticationException(\"Failed to authenticate with qBittorrent.\", ex);\n                    }\n\n                    throw new DownloadClientException(\"Failed to connect to qBittorrent, check your settings.\", ex);\n                }\n                catch (Exception ex)\n                {\n                    throw new DownloadClientException(\"Failed to connect to qBittorrent, please check your settings.\", ex);\n                }\n            }\n\n            AuthenticateClient(requestBuilder, settings);\n\n            var request = requestBuilder.Build();\n            request.LogResponseContent = true;\n            request.SuppressHttpErrorStatusCodes = [HttpStatusCode.Forbidden];\n\n            try\n            {\n                var response = _httpClient.Execute(request);\n\n                if (response.StatusCode == HttpStatusCode.Forbidden)\n                {\n                    _logger.Debug(\"Authentication required, logging in.\");\n\n                    AuthenticateClient(requestBuilder, settings, true);","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/Sonarr/Sonarr/blob/da2284d7eaab22ed9b2ca698af690148d691e967/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs#L384-L420","documentation":"Thrown by QBittorrentProxyV2.ProcessRequest when API key authentication is in use and a non-HttpException error occurs during request execution. This is the catch-all for unexpected errors — raw socket exceptions, TLS handshake failures not wrapped as HttpException, timeouts, or other runtime errors.","triggerScenarios":"Any Exception (not HttpException) thrown by _httpClient.Execute when settings.ApiKey is set — socket-level error, TLS exception, operation timeout, or unexpected runtime error.","commonSituations":"Network timeout; socket exception from a dropped connection; TLS/SSL handshake error; DNS resolution failure; unexpected null reference or serialization error in the HTTP layer.","solutions":["Inspect the inner Exception's type and message for the specific failure.","Verify network connectivity and stability to qBittorrent.","Check application logs for the full stack trace.","If TLS-related, verify certificate configuration and system trust store."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight network check to catch transport issues early\nusing (var tcpClient = new TcpClient())\n{\n    await tcpClient.ConnectAsync(settings.Host, settings.Port);\n}","typeGuard":"static bool IsNonHttpException(DownloadClientException ex) =>\n    ex.InnerException is not HttpException && ex.InnerException is not WebException;","tryCatchPattern":"try\n{\n    proxy.GetTorrents(settings);\n}\ncatch (DownloadClientException ex) when (ex.InnerException is not HttpException)\n{\n    _logger.Error(ex.InnerException, \"Unexpected non-HTTP error contacting qBittorrent with API key\");\n    throw;\n}","preventionTips":["Log the full inner exception type and message for diagnosis.","Perform a pre-flight connectivity check to catch transport issues early.","Monitor for TLS/socket errors that may indicate network configuration problems.","Review the application's HTTP client configuration (timeouts, TLS settings)."],"tags":["qbittorrent","network","api-key","download-client","v2-api"],"backgroundTag":null,"analyzedSha":"da2284d7eaab22ed9b2ca698af690148d691e967","analyzedAt":"2026-08-13T15:53:02.562Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}