{"record":{"id":"6f925f24086715ce","repo":"HelloZeroNet/ZeroNet","slug":"invalid-response-r-s","errorCode":null,"errorMessage":"Invalid response: %r (%s)","messagePattern":"Invalid response: %r \\((.+?)\\)","errorType":"exception","errorClass":"AnnounceError","httpStatus":null,"severity":"error","filePath":"plugins/AnnounceBitTorrent/AnnounceBitTorrentPlugin.py","lineNumber":146,"sourceCode":"            req.close()\n            req = None\n\n        if not response:\n            raise AnnounceError(\"No response after %.0fs\" % (time.time() - s))\n\n        # Decode peers\n        try:\n            peer_data = bencode_open.loads(response)[b\"peers\"]\n            response = None\n            peer_count = int(len(peer_data) / 6)\n            peers = []\n            for peer_offset in range(peer_count):\n                off = 6 * peer_offset\n                peer = peer_data[off:off + 6]\n                addr, port = struct.unpack('!LH', peer)\n                peers.append({\"addr\": socket.inet_ntoa(struct.pack('!L', addr)), \"port\": port})\n        except Exception as err:\n            raise AnnounceError(\"Invalid response: %r (%s)\" % (response, Debug.formatException(err)))\n\n        return peers\n","sourceCodeStart":128,"sourceCodeEnd":149,"githubUrl":"https://github.com/HelloZeroNet/ZeroNet/blob/454c0b2e7e000fda7000cba49027541fbf327b96/plugins/AnnounceBitTorrent/AnnounceBitTorrentPlugin.py#L128-L149","documentation":"The HTTP tracker replied, the body was bencode-decoded and b\"peers\" extracted, but parsing the 6-byte-per-peer compact format (unpack '!LH' / inet_ntoa) threw an exception. The plugin wraps it in AnnounceError(\"Invalid response: %r (%s)\") including the raw response and the formatted exception.","triggerScenarios":"peer_data length is not a multiple of 6 (truncated body, HTML error page that happened to bencode-decode, dict-style peers response instead of compact string), or peer_data is a dict/list not bytes so len()/slicing misbehaves.","commonSituations":"Trackers returning non-compact peer lists (dict with peer id fields) when compact=1 isn't honored; trackers returning error bencode like {b'failure reason': ...} with no b'peers'; proxy-injected HTML corrupting the body.","solutions":["Read the exception detail and raw response in the message — a 'failure reason' payload means the tracker rejected the announce.","Ensure the announce URL requests compact responses (peer batching) as this parser only handles 6-byte compact peers.","Check whether tracker returned dict-style peers and add handling for that format.","Switch to a working tracker in the site's tracker list.","Verify no proxy is rewriting the response body."],"exampleFix":"// before\npeer_data = bencode_open.loads(response)[b\"peers\"]\n// after\nparsed = bencode_open.loads(response)\nif not isinstance(parsed.get(b\"peers\"), (bytes, bytearray)):\n    raise AnnounceError(\"Tracker failure: %r\" % parsed)\npeer_data = parsed[b\"peers\"]","handlingStrategy":"validation","validationCode":"parsed = bencode_open.loads(response)\npeer_data = parsed.get(b\"peers\")\nif isinstance(peer_data, dict):\n    raise ValueError(\"Tracker returned non-compact peers dict\")\nif not isinstance(peer_data, (bytes, bytearray)) or len(peer_data) % 6 != 0:\n    raise ValueError(\"Peers payload not 6-byte aligned compact format\")","typeGuard":"def is_compact_peer_list(peer_data):\n    return isinstance(peer_data, (bytes, bytearray)) and len(peer_data) % 6 == 0","tryCatchPattern":"try:\n    peers = announce_plugin.announceTrackerHttp(tracker_address, file_info)\nexcept AnnounceError as e:\n    log.warning(\"Unparseable tracker response: %s\" % e)\n    peers = []","preventionTips":["Always request compact peer responses in the announce URL","Check for b'failure reason' in bencode replies before parsing peers","Verify response body is pure bencode (no proxy-injected HTML)","Handle dict-style (non-compact) peer responses as a fallback"],"tags":["http","tracker","bencode","protocol","parse-error"],"backgroundTag":"invalid-tracker-response","analyzedSha":"454c0b2e7e000fda7000cba49027541fbf327b96","analyzedAt":"2026-09-02T19:46:57.278Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}