{"record":{"id":"151ca43c1ce6e890","repo":"SeleniumHQ/selenium","slug":"unexpected-response-code-code-content-type","errorCode":null,"errorMessage":"unexpected response, code=#{code}, content-type=#{content_type.inspect}","messagePattern":"unexpected response, code=#(.+?), content-type=#(.+?)","errorType":"exception","errorClass":"Error::WebDriverError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/remote/http/common.rb","lineNumber":152,"sourceCode":"            raise Error::WebDriverError,\n                  \"Unable to encode string to UTF-8: #{e.message}. \" \\\n                  \"String encoding: #{str.encoding}, content: #{str.inspect}\"\n          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":134,"sourceCodeEnd":166,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/remote/http/common.rb#L134-L166","documentation":"Raised as Error::WebDriverError by Http::Common#create_response when the response has a non-JSON content-type, is not a 204 (No Content), and the body is empty. This is the catch-all for unexpected HTTP responses that the client cannot parse into a W3C response — neither JSON to parse nor an explicit no-content status.","triggerScenarios":"The server returns an HTML error page with a non-JSON content-type but empty body. A 200 response with content-type text/html and no body. A 302 redirect body that was consumed. An intermediate proxy returning an empty error page.","commonSituations":"Pointing the WebDriver client at the wrong URL (e.g. a web app root instead of the Selenium Server /wd/hub endpoint). A firewall or WAF returning empty blocking responses. Server misconfiguration returning wrong content-types. Authentication challenges (401) with empty bodies from proxies.","solutions":["Verify the remote URL points to the correct Selenium Server endpoint (e.g. http://host:4444 or with /wd/hub if required by server version).","Check if a proxy, firewall, or WAF is intercepting requests to the remote endpoint.","Enable header debug logging (id: :header) to inspect the full response content-type and code.","Curl the endpoint directly to see what it returns: curl -v http://host:4444/status."],"exampleFix":"# before\ndriver = Selenium::WebDriver.for(:remote, url: 'http://grid:4444/wd/hub', ...)\n# server returns text/html empty body (wrong endpoint)\n\n# after — verify the correct endpoint\ndriver = Selenium::WebDriver.for(:remote, url: 'http://grid:4444', ...)\n# confirm with: curl -s http://grid:4444/status","handlingStrategy":"validation","validationCode":"# Validate the remote URL is reachable and returns a proper status:\nrequire 'net/http'\nuri = URI(server_url + '/status')\nresp = Net::HTTP.get_response(uri)\nraise 'Unexpected endpoint' 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  raise \"Remote endpoint #{server_url} is not a valid Selenium Server\"\nend","preventionTips":["Verify the remote URL points to a Selenium Server endpoint before driver creation.","Curl the /status endpoint to confirm it returns JSON.","Check for proxies, firewalls, or WAFs intercepting grid traffic."],"tags":["http-response","unexpected-response","config-mistake","network"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}