Reading curl Proxy Errors: Exit Codes 5, 7, 28, 56 and 97
By the ProxyV4 Engineering Team · Updated:
curl: (56) Proxy CONNECT aborted means curl reached the proxy and sent its CONNECT request, but the proxy closed the connection without answering. It is one of five exit codes that cover nearly every proxy failure, and each points at a different hop: resolving the proxy (5), connecting to it (7), waiting on it (28), the CONNECT exchange (56) or a SOCKS handshake (97). Run the command again with -v and the last few lines tell you which one you hit.
Exit code lookup
Check the number with echo $? right after the command (or $LASTEXITCODE in PowerShell). Read the message as well as the number: curl 8.20.0 moved a refused CONNECT (CONNECT tunnel failed, response NNN) from code 56 to code 7, so the same proxy problem can carry a different number on different machines. Check yours with curl --version.
| Code | Typical message | Hop that failed |
|---|---|---|
| 5 | Could not resolve proxy: HOST | DNS lookup of the proxy hostname |
| 7 | Failed to connect to IP port PORT ... Couldn't connect to server; from curl 8.20.0 also CONNECT tunnel failed, response NNN | TCP connection to the proxy, or (newer curl) a refused CONNECT |
| 28 | Failed to connect ... Timeout was reached or Operation timed out | No answer in time, at connect or later |
| 56 | Proxy CONNECT aborted; before curl 8.20.0 also CONNECT tunnel failed, response 407 | The CONNECT exchange with an HTTP proxy |
| 97 | User was rejected by the SOCKS5 server and similar | SOCKS handshake (curl 7.73.0 and later) |
Code by code: the -v signature and the fix
curl (5) could not resolve proxy
Verbose output stops at * Could not resolve proxy: HOST before any Trying line. curl never found an address, so the proxy was never contacted. Check the hostname with getent hosts HOST or nslookup HOST. With numeric proxy IPs this code usually means something else supplied the proxy: look for a misspelled http_proxy, HTTPS_PROXY or ALL_PROXY variable with env | grep -i proxy. A whole ip:port:user:pass line pasted into -x tends to fail with a URL or port parsing error instead; split it first.
curl (7) failed to connect to proxy
You will see * Trying IP:PORT... followed by Connection refused or Couldn't connect to server. The host answered and nothing listens on that port, or a firewall rejected the packet. Test the socket alone with nc -vz IP PORT. Common causes: an expired proxy, a port that changed after a protocol switch, or an outbound firewall on the server you are testing from. Older curl releases, before 7.73.0, also reported SOCKS handshake failures as 7, so on an old system read the message text, not just the number. On curl 8.20.0 and later, a 7 that follows a CONNECT line in the trace is a refusal from the proxy, covered under the tunnel-failed heading below.
curl (28) timeouts
Where the clock ran out matters. If * Connected to IP never appears, the proxy did not accept the TCP connection in time; packets are probably being dropped rather than refused, which points to a wrong IP or a firewall. If the connection succeeded and the timeout came later, the proxy or the destination is slow. Separate the two limits with --connect-timeout 10 --max-time 30, and see the proxy timeout guide for network-side causes.
curl (56) Proxy CONNECT aborted
In the trace you see > CONNECT example.com:443 HTTP/1.1, then no < HTTP/1.1 reply line, then the abort. The proxy accepted TCP and hung up instead of answering. The most frequent cause is a protocol mismatch: you used http:// (or no scheme) against a port that only speaks SOCKS5, so the proxy reads an HTTP request where it expected a SOCKS greeting and drops the connection. Try the same line as socks5h://. Other causes are a proxy refusing your source address, a proxy at its connection limit, or a middlebox resetting the stream, which can also surface as Recv failure: Connection reset by peer under the same code 56.
CONNECT tunnel failed, response NNN (56, or 7 in newer curl)
Here the proxy did answer, with a refusal. curl releases before 8.20.0 exit with 56; 8.20.0 and later exit with 7, with the same message. The number in the message is the proxy's HTTP status. 407 means the login is missing or wrong; the 407 guide covers it in depth. 502 or 503 means the proxy could not reach the destination. 403 usually means the proxy's policy refused that host or port.
curl (97) proxy handshake failed
Code 97 is reserved for proxy handshake errors and appears with SOCKS proxies. The message names the step. No authentication method was acceptable means the server requires a login you did not send. User was rejected by the SOCKS5 server means the username or password is wrong. cannot complete SOCKS5 connection to HOST (worded Can't complete in older releases) means the proxy could not open the destination. A complaint about an invalid version in the initial SOCKS5 response means the port is not speaking SOCKS5 at all, usually because it is set to HTTP only.
407 replies that do not fail the command
A 407 only fails the command for https:// targets, where curl must tunnel (exit 56, or 7 from curl 8.20.0). For a plain http:// URL, the proxy's 407 page is a normal response: curl prints it and exits with 0, which makes a broken login look like success in a script. Add --fail (exit 22 on HTTP errors) and print the status explicitly:
curl -s -o /dev/null --fail -w '%{http_code}\n' \
-x http://IP:PORT -U 'USER:PASS' http://example.comIn the -v output, check for a > Proxy-Authorization: Basic line before the 407. If it is missing, curl sent no credentials at all, which points at the command or the variable that built it, not the password.
Flags that change the outcome
--proxy-user and special characters
-U 'USER:PASS' (long form --proxy-user) keeps credentials out of the proxy URL, so @, # or : in a password need no percent-encoding. Single quotes stop the shell from expanding $ or !. If you prefer the URL form, encode the password: @ becomes %40.
socks5:// versus socks5h://
With socks5://, curl resolves the destination hostname locally and hands the proxy an IP address. With socks5h://, the proxy resolves it. Use socks5h:// unless you have a reason not to: it avoids local DNS leaks and fixes destinations your local resolver cannot see.
--proxy-insecure is not -k
-k skips certificate checks for the destination site. --proxy-insecure skips them for the proxy itself, and only matters when the proxy URL starts with https://, meaning TLS to the proxy. Neither helps when you wrote https:// for a plain HTTP proxy; that fails with exit 35 and a wrong version number message. Change the proxy scheme to http://; the site's own HTTPS still runs end to end through the tunnel.
Verify a proxy line before you depend on it
The simplest way to keep all five codes out of production is to test each line once with a command that reports the exit IP:
curl -sS --connect-timeout 10 -m 30 -x http://IP:PORT -U 'USER:PASS' \
https://proxyv4.com/api/my-ip; echo " exit=$?"A printed address equal to the proxy IP and exit=0 means resolution, connection, login and tunnel all work. For batches without a shell loop, the proxy checker runs the same test on a pasted list. The cURL setup guide has the full command set, including timing checks.
When you buy, buy so this test stays boring. ProxyV4 private datacenter IPv4 proxies arrive as one ip:port:user:pass line, support HTTP(S) and SOCKS5 with username and password, and let you run both protocols on the same port from the order page, which removes the protocol mismatch behind many code 56 and 97 errors. The IP stays the same when renewed before expiry, and traffic is not metered. They will not suit you if you need UDP without checking with support first, or a fresh IP on every request. Live per-IP prices are on the pricing page; order one IP, run the command above, then scale.
Triage in a script
If you test many proxies, map the exit code to the hop instead of logging raw numbers:
while IFS=: read -r ip port user pass; do
curl -s -o /dev/null --connect-timeout 10 -m 30 \
-x "http://$ip:$port" -U "$user:$pass" https://example.com
case $? in
0) r="ok" ;;
5) r="proxy name did not resolve" ;;
7) r="refused: wrong port, proxy down, or CONNECT rejected (curl 8.20+)" ;;
28) r="timeout" ;;
56) r="CONNECT refused or aborted: check login and protocol mode" ;;
97) r="SOCKS handshake failed" ;;
*) r="other" ;;
esac
echo "$ip:$port $r"
done < proxies.txtFrequently asked questions
What does curl error 56 mean with a proxy?
Code 56 is a receive failure. With a proxy it almost always means the CONNECT step failed: either the proxy closed the connection (CONNECT aborted) or, in curl releases before 8.20.0, replied with an error status such as 407 or 502. Newer curl reports that second case as code 7.
Does -k fix proxy SSL errors?
Only for the destination's certificate. Certificate problems with an https:// proxy need --proxy-insecure, and a plain HTTP proxy should simply be addressed with http://.
Why does curl work but my browser does not with the same SOCKS5 proxy?
curl supports SOCKS5 username and password login, while Chrome and other Chromium browsers do not. Use the HTTP mode of the proxy in Chromium browsers.
Which curl version introduced exit code 97?
curl 7.73.0 added CURLE_PROXY (97) for proxy handshake errors. Earlier versions report most of the same SOCKS failures as code 7.
Can I switch a ProxyV4 proxy between HTTP and SOCKS5?
Yes. On the order page in the dashboard choose HTTP only, SOCKS5 only or both on the same port, then copy the line again because the port can change.
Verify any line with one curl command
ProxyV4 private IPv4 proxies come as one ip:port:user:pass line with HTTP(S) and SOCKS5 support and unmetered traffic. Order a single IP, test it with the command above, then buy more.
See live prices