{"record":{"id":"2e807e50d8264670","repo":"SeleniumHQ/selenium","slug":"unexpected-response-code-code-content-type-2e807e","errorCode":null,"errorMessage":"unexpected response, code=#{code}, content-type=#{content_type.inspect}\n#{body}","messagePattern":"unexpected response, code=#(.+?), content-type=#(.+?)\n#(.+?)","errorType":"exception","errorClass":"Error::WebDriverError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/remote/http/common.rb","lineNumber":155,"sourceCode":"          end\n\n          def create_response(code, body, content_type)\n            code = code.to_i\n            body = body.to_s.strip\n            content_type = content_type.to_s\n            WebDriver.logger.debug(\"<- #{body}\", id: :command)\n\n            if content_type.include? CONTENT_TYPE\n              raise Error::WebDriverError, \"empty body: #{content_type.inspect} (#{code})\\n#{body}\" if body.empty?\n\n              Response.new(code, JSON.parse(body))\n            elsif code == 204\n              Response.new(code)\n            else\n              msg = if body.empty?\n                      \"unexpected response, code=#{code}, content-type=#{content_type.inspect}\"\n                    else\n                      \"unexpected response, code=#{code}, content-type=#{content_type.inspect}\\n#{body}\"\n                    end\n\n              raise Error::WebDriverError, msg\n            end\n          end\n        end # Common\n      end # Http\n    end # Remote\n  end # WebDriver\nend # Selenium\n","sourceCodeStart":137,"sourceCodeEnd":166,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/remote/http/common.rb#L137-L166","documentation":"Raised as Error::WebDriverError by Http::Common#create_response when the response has a non-JSON content-type, is not a 204, and the body is non-empty. Unlike the empty-body variant, this includes the response body text so the developer can see what the server actually returned — typically an HTML error page, a proxy error, or a misrouted response.","triggerScenarios":"The server returns an HTML 404/500 error page. A reverse proxy returns an HTML error (e.g. nginx 502 Bad Gateway). The WebDriver client hits a non-Selenium HTTP service. The Selenium Server returns an HTML landing page instead of a JSON API response.","commonSituations":"Wrong URL — hitting a web server instead of the Selenium Server. Grid hub down and a load balancer returning an HTML error page. Selenium Server not started but something else listening on port 4444. Authentication pages from corporate proxies. Version mismatch where the server endpoint path changed.","solutions":["Read the response body in the error message — it usually identifies what service answered (HTML title, proxy name).","Verify the remote URL and path are correct for your Selenium Server version.","Ensure the Selenium Server / Grid is actually running and healthy: curl http://host:4444/status.","Check for corporate proxies or VPNs intercepting the connection to the grid."],"exampleFix":"# The error body will say e.g. \"<html><title>502 Bad Gateway</title>...\"\n# Fix: ensure the Selenium Grid is running and reachable\n# $ curl -s http://grid:4444/status | jq .value.ready\n# If false or unreachable, start/restart the grid.","handlingStrategy":"try-catch","validationCode":"# Pre-flight check: confirm the endpoint is a Selenium Server\nrequire 'net/http'\nuri = URI(server_url + '/status')\nresp = Net::HTTP.get_response(uri)\nraise \"Endpoint returned #{resp.content_type}, expected JSON\" unless resp.content_type.include?('application/json')","typeGuard":null,"tryCatchPattern":"begin\n  Selenium::WebDriver.for(:remote, url: server_url, options: opts)\nrescue Selenium::WebDriver::Error::WebDriverError => e\n  raise unless e.message.include?('unexpected response')\n  # e.message contains the HTML body — read it to identify the service\n  raise \"Not a Selenium Server at #{server_url}: #{e.message}\"\nend","preventionTips":["Read the response body in the error message to identify the service that answered.","Verify the Selenium Server / Grid is running: curl http://host:4444/status.","Ensure no other service is listening on port 4444.","Check corporate proxies or VPNs are not intercepting grid traffic."],"tags":["http-response","unexpected-response","server-error","config-mistake"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}