{"record":{"id":"e43049abff4555de","repo":"HelloZeroNet/ZeroNet","slug":"invalid-response-r","errorCode":null,"errorMessage":"Invalid response: %r","messagePattern":"Invalid response: %r","errorType":"exception","errorClass":"AnnounceError","httpStatus":null,"severity":"error","filePath":"plugins/AnnounceBitTorrent/AnnounceBitTorrentPlugin.py","lineNumber":69,"sourceCode":"            raise AnnounceError(\"Udp trackers not available with proxies\")\n\n        ip, port = tracker_address.split(\"/\")[0].split(\":\")\n        tracker = UdpTrackerClient(ip, int(port))\n        if helper.getIpType(ip) in self.getOpenedServiceTypes():\n            tracker.peer_port = self.fileserver_port\n        else:\n            tracker.peer_port = 0\n        tracker.connect()\n        if not tracker.poll_once():\n            raise AnnounceError(\"Could not connect\")\n        tracker.announce(info_hash=self.site.address_sha1, num_want=num_want, left=431102370)\n        back = tracker.poll_once()\n        if not back:\n            raise AnnounceError(\"No response after %.0fs\" % (time.time() - s))\n        elif type(back) is dict and \"response\" in back:\n            peers = back[\"response\"][\"peers\"]\n        else:\n            raise AnnounceError(\"Invalid response: %r\" % back)\n\n        return peers\n\n    def httpRequest(self, url):\n        headers = {\n            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',\n            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n            'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',\n            'Accept-Encoding': 'none',\n            'Accept-Language': 'en-US,en;q=0.8',\n            'Connection': 'keep-alive'\n        }\n\n        req = urllib.request.Request(url, headers=headers)\n\n        if config.trackers_proxy == \"tor\":\n            tor_manager = self.site.connection_server.tor_manager\n            handler = sockshandler.SocksiPyHandler(socks.SOCKS5, tor_manager.proxy_ip, tor_manager.proxy_port)","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/HelloZeroNet/ZeroNet/blob/454c0b2e7e000fda7000cba49027541fbf327b96/plugins/AnnounceBitTorrent/AnnounceBitTorrentPlugin.py#L51-L87","documentation":"After the UDP announce, poll_once() returned something, but it is neither None/empty nor a dict containing a \"response\" key. The plugin raises AnnounceError(\"Invalid response: %r\") with the raw payload. This guards the shape of the decoded bencode UDP reply before reading back[\"response\"][\"peers\"].","triggerScenarios":"Tracker replies with an error packet (e.g. b'error': b'...'), a malformed/non-bencode datagram, or an intermediate device (captive portal, DPI box) sends junk UDP data that gets decoded into an unexpected object.","commonSituations":"Trackers rejecting announces with error messages (wrong info_hash, banned client); responses from a different socket/peer landing on the same port; corrupted datagrams on lossy networks.","solutions":["Inspect the %r value in the message — if it contains an 'error' key, the tracker rejected the announce; read its reason.","Verify the site's address_sha1/info_hash is valid and the tracker supports it.","Use alternative trackers; drop trackers that consistently return invalid responses.","Ensure the UDP socket is only receiving from the tracker (port conflicts)."],"exampleFix":"// before\nelse:\n    raise AnnounceError(\"Invalid response: %r\" % back)\n// after\nelif type(back) is dict and \"error\" in back:\n    self.site.log.warning(\"Tracker error: %r\" % back)\n    return []\nelse:\n    raise AnnounceError(\"Invalid response: %r\" % back)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def is_valid_announce_response(back):\n    return isinstance(back, dict) and \"response\" in back and isinstance(back[\"response\"], dict)","tryCatchPattern":"try:\n    peers = announce_plugin.announceTrackerUdp(tracker_address, file_info)\nexcept AnnounceError as e:\n    log.warning(\"Invalid tracker reply: %s\" % e)\n    peers = []","preventionTips":["Bind the UDP socket to a dedicated port to avoid stray datagrams","Log raw responses (the %r payload) to identify trackers sending error packets","Drop trackers that repeatedly return non-standard replies","Keep client protocol/format aligned with tracker expectations"],"tags":["network","udp","tracker","protocol","malformed-response"],"backgroundTag":"invalid-tracker-response","analyzedSha":"454c0b2e7e000fda7000cba49027541fbf327b96","analyzedAt":"2026-09-02T19:46:57.278Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}