{"record":{"id":"40a18d9da8648610","repo":"arduino/Arduino","slug":"wrong-server-response-s-s","errorCode":null,"errorMessage":"Wrong server response: %s %s","messagePattern":"Wrong server response: (.+?) (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"arduino-core/src/processing/app/i18n/python/requests/packages/urllib3/contrib/ntlmpool.py","lineNumber":105,"sourceCode":"        ServerChallenge, NegotiateFlags = \\\n            ntlm.parse_NTLM_CHALLENGE_MESSAGE(auth_header_value)\n        auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(ServerChallenge,\n                                                         self.user,\n                                                         self.domain,\n                                                         self.pw,\n                                                         NegotiateFlags)\n        headers[req_header] = 'NTLM %s' % auth_msg\n        log.debug('Request headers: %s' % headers)\n        conn.request('GET', self.authurl, None, headers)\n        res = conn.getresponse()\n        log.debug('Response status: %s %s' % (res.status, res.reason))\n        log.debug('Response headers: %s' % dict(res.getheaders()))\n        log.debug('Response data: %s [...]' % res.read()[:100])\n        if res.status != 200:\n            if res.status == 401:\n                raise Exception('Server rejected request: wrong '\n                                'username or password')\n            raise Exception('Wrong server response: %s %s' %\n                            (res.status, res.reason))\n\n        res.fp = None\n        log.debug('Connection established')\n        return conn\n\n    def urlopen(self, method, url, body=None, headers=None, retries=3,\n                redirect=True, assert_same_host=True):\n        if headers is None:\n            headers = {}\n        headers['Connection'] = 'Keep-Alive'\n        return super(NTLMConnectionPool, self).urlopen(method, url, body,\n                                                       headers, retries,\n                                                       redirect,\n                                                       assert_same_host)\n","sourceCodeStart":87,"sourceCodeEnd":121,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/processing/app/i18n/python/requests/packages/urllib3/contrib/ntlmpool.py#L87-L121","documentation":"In the same final-leg check of ntlmpool._new_conn, any non-200 status that is not 401 raises 'Wrong server response: <status> <reason>'. The NTLM handshake succeeded at the transport level but the server returned something the pool cannot interpret as an authenticated connection, so it aborts with this generic Exception.","triggerScenarios":"Completing the NTLM authenticate exchange but receiving e.g. 403 (insufficient permissions on the target resource), 404/500 (bad target path or server error), or 502/503 from an intermediary during an NTLMConnectionPool request.","commonSituations":"Authenticated user lacks rights to the requested resource (403); the configured host/path on the pool is wrong (404); upstream application error (500); corporate proxy returning 502/503 mid-handshake.","solutions":["Read the logged status/reason (log.debug prints it) and address the underlying HTTP status: 403 → fix permissions, 404 → fix the host/path configured on the pool.","Retry the request — NTLM connection setup can race with server-side state; a fresh request sometimes completes cleanly.","Bypass intermediaries (proxy/load balancer) or check their logs if the status is 5xx and direct connection works.","If the server intermittently drops NTLM support, fall back to a plain pool or a different auth scheme the server reliably offers."],"exampleFix":"// before (403 from wrong path)\npool.request('GET', '/admin/config')  # user has no rights\n// after\npool.request('GET', '/public/status')  # resource the authenticated user may access","handlingStrategy":"retry","validationCode":"def check_resource_available(base_url, path):\n    import requests\n    r = requests.head(base_url + path, allow_redirects=False)\n    return r.status_code < 400, r.status_code","typeGuard":"def is_auth_handshake_success(status):\n    return status == 200","tryCatchPattern":"import time\nfor attempt in range(3):\n    try:\n        resp = ntlm_pool.urlopen('GET', path)\n        break\n    except Exception as e:\n        if 'Wrong server response' in str(e) and attempt < 2:\n            time.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["Log res.status and res.reason at INFO on failure so the underlying HTTP status is actionable.","Verify the target path/resource is accessible to the authenticated account (avoid 403).","Check proxy/load-balancer health when seeing 5xx during handshakes.","Use a plain unauthenticated HEAD request to validate the URL before NTLM handshakes."],"tags":["python","ntlm","http","server-error"],"backgroundTag":"http-error-status","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}