ytdl-org/youtube-dl · error · EOFError

{0} bytes missing

Error message

{0} bytes missing

What it means

Raised (EOFError) by sockssocket.recvall when the socket closes before the expected number of bytes for the current SOCKS handshake step have arrived. The message states how many bytes of the current read are still missing. It is a Python EOFError, not an ExtractorError, so it surfaces as an unexpected network failure during proxy negotiation.

Source

Thrown at youtube_dl/socks.py:126

    'type', 'host', 'port', 'username', 'password', 'remote_dns'))


class sockssocket(socket.socket):
    def __init__(self, *args, **kwargs):
        self._proxy = None
        super(sockssocket, self).__init__(*args, **kwargs)

    def setproxy(self, proxytype, addr, port, rdns=True, username=None, password=None):
        assert proxytype in (ProxyType.SOCKS4, ProxyType.SOCKS4A, ProxyType.SOCKS5)

        self._proxy = Proxy(proxytype, addr, port, username, password, rdns)

    def recvall(self, cnt):
        data = b''
        while len(data) < cnt:
            cur = self.recv(cnt - len(data))
            if not cur:
                raise EOFError('{0} bytes missing'.format(cnt - len(data)))
            data += cur
        return data

    def _recv_bytes(self, cnt):
        data = self.recvall(cnt)
        return compat_struct_unpack('!{0}B'.format(cnt), data)

    @staticmethod
    def _len_and_data(data):
        return compat_struct_pack('!B', len(data)) + data

    def _check_response_version(self, expected_version, got_version):
        if got_version != expected_version:
            self.close()
            raise InvalidVersionError(expected_version, got_version)

    def _resolve_address(self, destaddr, default, use_remote_dns):
        try:

View on GitHub (pinned to 956b8c5855)

Solutions

  1. Confirm the proxy really speaks SOCKS on that port: 'curl -x socks5h://host:port https://example.com'
  2. Check the scheme matches the proxy type (socks5:// vs socks4:// vs http://) in --proxy
  3. Try the proxy from another network/machine to rule out firewall resets
  4. Use a reliable proxy or retry — transient drops on free SOCKS servers are common

Example fix

# before
youtube-dl --proxy 'socks5://127.0.0.1:8080' URL   # 8080 is an HTTP proxy
# after
youtube-dl --proxy 'socks5://127.0.0.1:1080' URL   # actual SOCKS port
Defensive patterns

Strategy: retry

Validate before calling

import socket

def socks_port_alive(host, port, timeout=3):
    try:
        s = socket.create_connection((host, port), timeout)
        s.close()
        return True
    except OSError:
        return False

assert socks_port_alive(proxy_host, proxy_port), 'proxy unreachable before we start'

Try / catch

for attempt in range(3):
    try:
        ydl.download([url]); break
    except EOFError as e:
        if 'bytes missing' in str(e):
            continue  # transient drop during SOCKS handshake — retry
        raise

Prevention

When it happens

Trigger: Using --proxy socks4:// or socks5:// where the proxy (or an intermediary) closes the connection mid-handshake: wrong port serving a non-SOCKS protocol that resets, proxy process crashing, firewall/LB dropping the connection, or the server rejecting the client immediately.

Common situations: Pointing --proxy at an HTTP proxy port with a socks5:// scheme; overloaded or flaky public SOCKS proxies; NAT/firewall idle-kill during slow negotiations; proxy bound to a different address family.

Related errors


AI-assisted analysis of ytdl-org/youtube-dl@956b8c5855 (2026-08-14). Data as JSON: /api/errors/c0ae79ab949a16c3. Report an issue: GitHub.