{"record":{"id":"a406ef7d93ca61be","repo":"ytdl-org/youtube-dl","slug":"invalid-response-version-from-server-expected-0","errorCode":null,"errorMessage":"Invalid response version from server. Expected {0:02x} got {1:02x}","messagePattern":"Invalid response version from server\\. Expected (.+?) got (.+?)","errorType":"exception","errorClass":"InvalidVersionError","httpStatus":null,"severity":"error","filePath":"youtube_dl/socks.py","lineNumber":141,"sourceCode":"        while len(data) < cnt:\n            cur = self.recv(cnt - len(data))\n            if not cur:\n                raise EOFError('{0} bytes missing'.format(cnt - len(data)))\n            data += cur\n        return data\n\n    def _recv_bytes(self, cnt):\n        data = self.recvall(cnt)\n        return compat_struct_unpack('!{0}B'.format(cnt), data)\n\n    @staticmethod\n    def _len_and_data(data):\n        return compat_struct_pack('!B', len(data)) + data\n\n    def _check_response_version(self, expected_version, got_version):\n        if got_version != expected_version:\n            self.close()\n            raise InvalidVersionError(expected_version, got_version)\n\n    def _resolve_address(self, destaddr, default, use_remote_dns):\n        try:\n            return socket.inet_aton(destaddr)\n        except socket.error:\n            if use_remote_dns and self._proxy.remote_dns:\n                return default\n            else:\n                return socket.inet_aton(socket.gethostbyname(destaddr))\n\n    def _setup_socks4(self, address, is_4a=False):\n        destaddr, port = address\n\n        ipaddr = self._resolve_address(destaddr, SOCKS4_DEFAULT_DSTIP, use_remote_dns=is_4a)\n\n        packet = compat_struct_pack('!BBH', SOCKS4_VERSION, Socks4Command.CMD_CONNECT, port) + ipaddr\n\n        username = (self._proxy.username or '').encode('utf-8')","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/socks.py#L123-L159","documentation":"Raised as InvalidVersionError by sockssocket._check_response_version when the first byte of the server's response does not match the protocol-expected version byte (e.g. 0x05 for SOCKS5 handshake, 0x01 for the user-auth sub-negotiation). The socket is closed first, then the error reports expected vs got in hex.","triggerScenarios":"Talking SOCKS5 to something that is not a SOCKS5 server: an HTTP CONNECT proxy (responds 'HTTP/1.1 ...' — first byte 0x48), a SOCKS4-only server, or any service whose greeting does not start with the version byte. Also fires in the sub-auth step if the server sends an unexpected auth reply version.","commonSituations":"--proxy socks5:// used against an HTTP proxy port; SOCKS4 server addressed as socks5; misconfigured port forwarding to the wrong local service; some proxies that banner-greet with text.","solutions":["Test the endpoint with curl to identify what it actually speaks: 'curl -v -x socks5h://host:port ...' vs '-x http://host:port'","Change the --proxy scheme to match the real protocol (http://, socks4://, socks5://)","Verify the port number against the proxy's configuration","If the server is SOCKS4-only, use socks4:// or upgrade the server to SOCKS5"],"exampleFix":"# before\nyoutube-dl --proxy 'socks5://proxy.example.com:3128' URL  # 3128 = HTTP proxy\n# after\nyoutube-dl --proxy 'http://proxy.example.com:3128' URL","handlingStrategy":"validation","validationCode":"import socket\n\ndef endpoint_speaks_socks5(host, port, timeout=3):\n    s = socket.create_connection((host, port), timeout)\n    s.sendall(b'\\x05\\x01\\x00')          # greeting: 1 method, no-auth\n    resp = s.recv(2)\n    s.close()\n    return resp[:1] == b'\\x05'            # server must echo version 5\n\nassert endpoint_speaks_socks5(host, port), 'not a SOCKS5 server — fix scheme/port'","typeGuard":null,"tryCatchPattern":"try:\n    ydl.download([url])\nexcept Exception as e:\n    if type(e).__name__ == 'InvalidVersionError':\n        raise SystemExit('Proxy is not SOCKS5 on this port; check --proxy scheme and port')\n    raise","preventionTips":["Probe the first response byte once at startup: 0x05 means SOCKS5, 'H' means HTTP","Keep a documented mapping of proxy port to protocol in your config","Do not reuse proxy URLs across schemes when ports change"],"tags":["socks","proxy","protocol-mismatch","version-check"],"backgroundTag":null,"analyzedSha":"956b8c585591b401a543e409accb163eeaaa1193","analyzedAt":"2026-08-14T18:59:47.863Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}