Amazon holiday deals See deals →ad

Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

wget stream was too long: 10 Fixes That Work

If you’ve ever run wget and hit the cryptic “stream was too long” error, you know it stops a download dead in its tracks. This listicle covers the ten most effective fixes, from simple command-line tweaks to network-level adjustments. It’s written for Linux users, sysadmins, and anyone who relies on wget for scripting or bulk downloads. Each fix is explained with real commands and specifics, so you can apply them immediately.

1. Use –max-redirect to Control Redirect Loops

The error often occurs when a server sends an endless chain of redirects. By default, wget follows up to 20 redirects, but a misconfigured server can loop indefinitely. Set a lower limit with --max-redirect=5 to stop the loop early and get a clearer error message. This also prevents wget from consuming memory and bandwidth on a pointless chase.

2. Add –no-check-certificate for SSL/TLS Issues

Sometimes the “stream too long” error is actually a side effect of a TLS handshake failure or a server sending malformed SSL data. While not a security best practice, using --no-check-certificate bypasses certificate validation, which can resolve the issue if the server has an expired or self-signed certificate. Use this only for trusted or internal servers, and consider updating your CA certificates instead.

3. Set a Timeout with –timeout

A server that stalls mid-response can cause wget to hang, and the connection may be dropped, leading to a “stream was too long” error. Set a global timeout with --timeout=30 to abort after 30 seconds of inactivity. This is especially useful for flaky connections or servers that keep the socket open without sending data.

4. Limit Download Size with –max-filesize

If you’re downloading a file that exceeds your expectation, wget might misinterpret the stream length. Use --max-filesize=100m to abort if the file is larger than 100 MB. This doesn’t fix the root cause, but it prevents wget from wasting time on a file that’s too large, and it can reveal that the server is sending a continuous stream instead of a proper file.

5. Switch to HTTP/1.1 with –no-http-keep-alive

HTTP keep-alive can cause issues with certain servers that mishandle persistent connections. Disable it with --no-http-keep-alive to force a fresh connection for each request. This often resolves the error when the server is misreporting content-length or closing connections unexpectedly.

6. Use –header to Send a Proper User-Agent

Some servers block or misbehave when they see the default wget user agent. Send a browser-like user agent with --header="User-Agent: Mozilla/5.0". This can trick the server into sending a normal response instead of a malformed stream, which is a common cause of the error on CDNs and streaming endpoints.

7. Try –spider to Diagnose the URL

Run wget --spider URL to check the headers without downloading. This shows you the server’s response, including content-length and transfer-encoding. If the server sends Transfer-Encoding: chunked without proper termination, you’ll see it here. This diagnostic step helps you decide whether to use --no-http-keep-alive or another fix.

8. Use –retry-connrefused to Handle Intermittent Failures

If the server drops the connection mid-transfer, wget may report “stream was too long” instead of a connection reset. Add --retry-connrefused to automatically retry when the connection is refused. Combined with --tries=5, this can get you past transient network issues without manual intervention.

9. Force IPv4 with -4

IPv6 can cause subtle issues if your network or the server has misconfigured DNS. Force IPv4 with wget -4 URL. This is a quick test—if the download works with IPv4, the problem is likely IPv6-related. You can then adjust your system’s IPv6 settings or use -4 as a permanent workaround.

10. Use curl as a Fallback

When wget consistently fails with this error, curl is a reliable alternative. Curl handles streams differently and often succeeds where wget fails. Use curl -O URL to download a file. While not a fix for wget, it’s a practical solution when you need the file now and can debug wget later.

How to Choose

Start with the simplest fixes: test with --spider to see the server’s response, then try --no-http-keep-alive and a custom user agent. If the error persists, check for redirects with --max-redirect and timeouts. For SSL-related issues, try --no-check-certificate only if you trust the server. For network-level problems, test IPv4 and consider curl as a fallback. The right fix depends on the server’s behavior, so use the diagnostic steps to narrow it down.

Frequently Asked Questions

Q: What does “stream was too long” actually mean?
A: It means wget received more data than expected based on the Content-Length header, or the stream didn’t terminate properly. It’s often caused by server misconfiguration, redirect loops, or protocol mismatches.

Q: Can I ignore the error and still get the file?
A: Sometimes, but it’s risky. If wget aborts, the file may be incomplete. You can try resuming with -c, but if the stream is malformed, the resume may also fail.

Q: Is this error a security risk?
A: Not directly, but it can indicate a server that’s sending unexpected data. Be cautious if you’re downloading from an untrusted source—verify the file’s checksum before using it.

Q: Does using –no-check-certificate make the download unsafe?
A: It disables SSL certificate validation, which means you’re vulnerable to man-in-the-middle attacks. Only use it for internal or trusted servers, and prefer updating your CA certificates.

Q: Why does curl work when wget doesn’t?
A: Curl and wget handle HTTP streams differently, including redirects, chunked encoding, and keep-alive. Curl’s more flexible stream handling often bypasses the issue.

Q: Can I prevent this error in scripts?
A: Yes, add --tries=3 and --timeout=30 to your wget commands. Also, check the server’s response headers with --spider before downloading.

Final Thoughts

The “stream was too long” error is frustrating, but it’s rarely a dead end. By methodically applying the fixes above, you can usually get your download moving again. Start with diagnostics, then apply the most likely fix, and don’t hesitate to switch to curl if you’re in a hurry. With these ten solutions, you’re well-equipped to handle the error and keep your downloads flowing.

wget stream was too long: 10 Fixes That Work
Scroll to top