{"record":{"id":"7d3b062719596667","repo":"HelloZeroNet/ZeroNet","slug":"could-not-connect","errorCode":null,"errorMessage":"Could not connect","messagePattern":"Could not connect","errorType":"exception","errorClass":"AnnounceError","httpStatus":null,"severity":"error","filePath":"plugins/AnnounceBitTorrent/AnnounceBitTorrentPlugin.py","lineNumber":61,"sourceCode":"            handler = super(SiteAnnouncerPlugin, self).getTrackerHandler(protocol)\n        return handler\n\n    def announceTrackerUdp(self, tracker_address, mode=\"start\", num_want=10):\n        s = time.time()\n        if config.disable_udp:\n            raise AnnounceError(\"Udp disabled by config\")\n        if config.trackers_proxy != \"disable\":\n            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',","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/HelloZeroNet/ZeroNet/blob/454c0b2e7e000fda7000cba49027541fbf327b96/plugins/AnnounceBitTorrent/AnnounceBitTorrentPlugin.py#L43-L79","documentation":"AnnounceBitTorrentPlugin announces a site's peers via a UDP BitTorrent tracker. announceTrackerUdp calls tracker.connect() then poll_once(); if the first poll returns nothing (no UDP response / connect handshake failed), it raises AnnounceError(\"Could not connect\"). This means the tracker never responded to the initial connection, so the announce cannot proceed.","triggerScenarios":"The UDP tracker at the configured tracker address is unreachable or drops packets: tracker domain resolves wrong, UDP traffic blocked by firewall/NAT, tracker offline, or wrong port in the site's tracker list. tracker.poll_once() times out after tracker.connect().","commonSituations":"Firewalled/censored networks blocking UDP; dead public BitTorrent trackers; trackers configured in site's sites.json that no longer exist; IPv6 vs IPv4 mismatch (getIpType check sets peer_port=0 but tracker still unresponsive).","solutions":["Verify the tracker address is alive (e.g. test with a bittorrent client or dig/nc for the UDP port).","Check local firewall/NAT allows outbound UDP on the tracker port.","Wait and retry — announce is retried periodically and other trackers (AnnounceTrackers plugin) cover failures.","Replace the dead tracker in the site's tracker list.","Check Tor/transparent proxy config is not blocking UDP."],"exampleFix":"// before\ntracker.connect()\nif not tracker.poll_once():\n    raise AnnounceError(\"Could not connect\")\n// after\ntracker.connect()\nif not tracker.poll_once():\n    self.site.log.debug(\"UDP tracker %s unreachable, skipping\" % tracker_address)\n    return []  # let other trackers handle announce","handlingStrategy":"retry","validationCode":"import socket\nsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\nsock.settimeout(5)\ntry:\n    host, port = tracker_address.split(\":\")\n    sock.sendto(b\"probe\", (socket.gethostbyname(host), int(port)))\n    reachable = True\nexcept (socket.error, socket.gaierror):\n    reachable = False\nfinally:\n    sock.close()\nif not reachable:\n    skip_tracker(tracker_address)","typeGuard":null,"tryCatchPattern":"try:\n    peers = announce_plugin.announceTrackerUdp(tracker_address, file_info)\nexcept AnnounceError as e:\n    log.warning(\"UDP tracker %s failed: %s\" % (tracker_address, e))\n    peers = []  # other announce plugins will cover","preventionTips":["Validate tracker addresses resolve and respond to UDP before adding to site tracker list","Run periodic tracker health checks and drop dead ones","Keep multiple announce plugins enabled for redundancy","Ensure firewall/NAT permits outbound UDP"],"tags":["network","udp","tracker","bittorrent","timeout"],"backgroundTag":"tracker-connection-failed","analyzedSha":"454c0b2e7e000fda7000cba49027541fbf327b96","analyzedAt":"2026-09-02T19:46:57.278Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}