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
- Read the status code after "returned error:" first; it tells you which side to look at.
- 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.
- Add -L if the URL redirects, and check the URL and credentials.
- For 5xx errors, check the server and upstream logs.
Got a different message? Paste it into the error explainer.
Related errors
- curl: (18) transfer closed with outstanding read data remaining · The connection closed before the body finished
- curl: (47) Maximum (50) redirects followed · curl stopped in a redirect loop
- curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1) · The server reset an HTTP/2 stream
- unable to get local issuer certificate · The client can't find the certificate's issuer
- unable to verify the first certificate · The intermediate certificate is missing
- certificate has expired · The server certificate has expired
- self signed certificate in certificate chain · The chain ends in an untrusted root
- wrong version number · TLS spoken to something that isn't TLS
- curl: (6) Could not resolve host · The hostname doesn't resolve
- curl: (7) Failed to connect · The connection was refused or unreachable
- curl: (28) Operation timed out · The request timed out
- curl: (51) SSL: no alternative certificate subject name matches target host name · The certificate doesn't match the hostname