Skip to content
MtrXTools

curl: (22) The requested URL returned error

The server answered with an HTTP error status

Seen in curl with -f / --fail, scripts, Dockerfiles, CI pipelines

curl was run with --fail and the server replied with an HTTP status of 400 or higher, so curl exited with an error instead of printing the body.

Common causes

  • 404: the path is wrong or the file was moved or deleted.
  • 401 or 403: missing or rejected credentials, tokens or IP allow-listing.
  • 5xx: the server or an upstream behind it failed.
  • A redirect was not followed because -L was missing, and the final URL returned an error.

How to fix it

  1. Read the status code after "returned error:" first; it tells you which side to look at.
  2. Run curl -sS -o /dev/null -w "%{http_code}\n" -L URL to see the final status, or drop -f to see the error body.
  3. Add -L if the URL redirects, and check the URL and credentials.
  4. For 5xx errors, check the server and upstream logs.
See the status and redirect chain

Got a different message? Paste it into the error explainer.

Related errors

All 34 Command line & code errors