Skip to content

400 Bad Request: what it means and how to fix it

By the ProxyOnly team · 25 Nov 2026 · 5 min read

A 400 means the server could not parse your request. The four causes, how to tell them apart, and what to do as a visitor, a developer or a scraper.

A 400 Bad Request means the server refused to process your request because it could not understand it. RFC 9110 puts it as something the server perceives to be a client error, such as malformed syntax or deceptive request routing.

That wording matters. A 400 is not the server saying no. It is the server saying it could not read the question. The request never reached the application logic in most cases, which is why a 400 page is so often blank and unhelpful.

400 is not 401, 403 or 404

These get mixed up constantly, and the difference tells you where to look.

  • 400 Bad Request: the request is malformed. The server could not parse it.
  • 401 Unauthorized: parsed fine, but you need to authenticate. See 401 vs 403.
  • 403 Forbidden: parsed fine, you may be authenticated, and you still may not have it. See 403 Forbidden.
  • 404 Not Found: parsed fine, the path does not exist.
  • 422 Unprocessable Content: parsed fine, the syntax is valid, but the values do not make sense.

The 400 and 422 line is the one developers argue about. A useful rule: if the server could not turn the bytes into a request, that is 400. If it read the request and the data inside it was wrong, that is 422.

The four causes

Something in the request line or headers is malformed

Illegal characters in the URL, a header without a colon, a stray newline, two Content-Length headers that disagree. Most of this comes from code that builds requests by string concatenation rather than with a library.

The request is too large for the server's limits

This is the most common cause that has nothing to do with your code being wrong. Servers cap header size, and a request that exceeds the cap gets a 400 from the web server before your application sees it.

  • nginx uses large_client_header_buffers, 4 buffers of 8 KB by default.
  • Apache uses LimitRequestFieldSize, 8190 bytes per header by default.
  • Many CDNs and load balancers impose their own ceiling.

The usual culprit is cookies. A site that accumulates tracking cookies over months can push the Cookie header past 8 KB, and then every request from that browser fails with a 400 while the same page loads fine in a private window. That single symptom, works in incognito and fails in the normal window, is close to diagnostic.

The body does not match what was promised

You sent Content-Type: application/json and the body is not valid JSON. A trailing comma, a single quote, an unescaped newline inside a string. Many frameworks answer 400 for a JSON parse failure.

The server is rejecting the request on purpose

Some servers use 400 as a catch-all for requests they dislike: an unexpected Host header, a protocol mismatch, a malformed TLS SNI, or a bot filter that does not want to explain itself. Cloudflare's HTTP status code documentation lists its own 400-series behaviour, and an error page that mentions Cloudflare points at the edge rather than the origin.

If you are a visitor

  1. Check the address for a typo, especially an unencoded space or a stray character pasted from a chat message.
  2. Open the page in a private window. If it works there, your cookies for that site are the problem.
  3. Clear the cookies for that one site rather than all of them. Every browser offers this under site settings.
  4. Try another browser and another network to rule out an extension or a captive portal rewriting your traffic.

If you are building the API

Send a body that says what was wrong. A 400 with an empty body costs every one of your users an hour. This is enough:

{"error": "invalid_json", "detail": "Unexpected token at line 3, column 18"}

Then check three things in order. First, whether the request reached your application at all, because a 400 from nginx or your CDN never appears in your application log. Second, your header and body size limits against what clients actually send. Third, whether you are returning 400 where 422 would be more accurate, which matters because clients retry them differently.

If a scraper gets a 400

A 400 in a scraping job is almost always your request construction, not the target site being clever. Work through it in this order.

Build the URL with a library rather than by hand. urllib.parse.urlencode and requests's params argument encode spaces, ampersands and unicode correctly, and hand-built query strings do not.

import requests
params = {"q": "proxy server", "page": 2}
r = requests.get("https://httpbin.org/get", params=params, timeout=10)
print(r.status_code, r.json()["args"])

We ran that against httpbin and it returned 200 {'page': '2', 'q': 'proxy server'}, with the space encoded. The same URL concatenated by hand with the raw space in it is a malformed request line.

Next, print the request your client actually sent. In requests the prepared request is attached to the response:

r = requests.get("https://httpbin.org/get", params={"q": "x y"}, timeout=10)
print(r.request.url)
print(dict(r.request.headers))

Then shrink the request until it works. Drop your custom headers, then add them back one at a time. An oversized or malformed header you copied from a browser's developer tools is a frequent cause, especially a Cookie header pasted whole from a long browser session.

If the 400 only appears through a proxy, test the same request without one. A 400 that appears only on the proxied path usually means the request was rewritten in transit, and that is worth knowing before you spend an afternoon on your own code. Our own proxy errors guide covers the errors that genuinely do come from the proxy layer, such as 407, which a 400 is not.

What not to do

Do not retry a 400. Unlike a 429 or a 503, nothing about waiting changes the outcome. The request is malformed, and it will be malformed in ten seconds. Retrying a 400 in a loop wastes your time and the target's capacity, and on a rate-limited endpoint it can get your address blocked for behaviour that looks like an attack.

Rotating to a different IP will not help either. The request is wrong, not the sender.

Try it yourself

Create an account, add funds from US$1 and order a proxy in the country you need.

Keep reading