{"record":{"id":"1a4fba31f5ce95fc","repo":"HelloZeroNet/ZeroNet","slug":"random-error-site-exist","errorCode":null,"errorMessage":"Random error: site exist!","messagePattern":"Random error: site exist!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/User/User.py","lineNumber":101,"sourceCode":"            del(self.sites[address])\n            self.saveDelayed()\n            self.log.debug(\"Deleted site: %s\" % address)\n\n    def setSiteSettings(self, address, settings):\n        site_data = self.getSiteData(address)\n        site_data[\"settings\"] = settings\n        self.saveDelayed()\n        return site_data\n\n    # Get data for a new, unique site\n    # Return: [site_address, bip32_index, {\"auth_address\": \"xxx\", \"auth_privatekey\": \"xxx\", \"privatekey\": \"xxx\"}]\n    def getNewSiteData(self):\n        import random\n        bip32_index = random.randrange(2 ** 256) % 100000000\n        site_privatekey = CryptBitcoin.hdPrivatekey(self.master_seed, bip32_index)\n        site_address = CryptBitcoin.privatekeyToAddress(site_privatekey)\n        if site_address in self.sites:\n            raise Exception(\"Random error: site exist!\")\n        # Save to sites\n        self.getSiteData(site_address)\n        self.sites[site_address][\"privatekey\"] = site_privatekey\n        self.save()\n        return site_address, bip32_index, self.sites[site_address]\n\n    # Get BIP32 address from site address\n    # Return: BIP32 auth address\n    def getAuthAddress(self, address, create=True):\n        cert = self.getCert(address)\n        if cert:\n            return cert[\"auth_address\"]\n        else:\n            return self.getSiteData(address, create)[\"auth_address\"]\n\n    def getAuthPrivatekey(self, address, create=True):\n        cert = self.getCert(address)\n        if cert:","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/HelloZeroNet/ZeroNet/blob/454c0b2e7e000fda7000cba49027541fbf327b96/src/User/User.py#L83-L119","documentation":"getNewSiteData derives a new site private key from the master seed at a random bip32_index, converts it to an address, and asserts that address is unused. If the derived address already exists in self.sites (an astronomically unlikely collision, or a non-random index being reused), it raises 'Random error: site exist!' to prevent overwriting existing site data.","triggerScenarios":"Calling getNewSiteData (used when creating a new site or cloning) when the randomly chosen bip32_index maps to an address already registered in the user's sites — effectively a 1-in-100-million collision per attempt, or deterministic seeds/indexes being reused.","commonSituations":"Corrupted or duplicated sites.json causing repeated creation attempts to collide; users with extremely large numbers of sites; code paths that reuse the same master_seed and a previously used index.","solutions":["Simply retry — the index is random each call, so a second attempt will almost certainly succeed","Check users/sites.json for duplicate or stale entries of the conflicting address and remove/merge them","Patch the code to loop with a new random bip32_index instead of raising (wrap the collision check in a while loop)","Verify the master_seed is correct; a truncated/duplicated seed can reproduce identical addresses"],"exampleFix":"// before\nif site_address in self.sites:\n    raise Exception(\"Random error: site exist!\")\n// after\nwhile True:\n    bip32_index = random.randrange(2 ** 256) % 100000000\n    site_privatekey = CryptBitcoin.hdPrivatekey(self.master_seed, bip32_index)\n    site_address = CryptBitcoin.privatekeyToAddress(site_privatekey)\n    if site_address not in self.sites:\n        break","handlingStrategy":"retry","validationCode":"if site_address in user.sites:\n    # pick a different index before calling getNewSiteData\n    bip32_index = (bip32_index + 1) % 100000000","typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    try:\n        address, index, site_data = user.getNewSiteData()\n        break\n    except Exception as e:\n        if 'Random error: site exist' in str(e):\n            continue\n        raise","preventionTips":["Retry on this error — collisions are astronomically unlikely","Keep users/sites.json intact and avoid duplicate site entries","Do not reuse or truncate master seeds","If creating many sites, monitor for repeated collisions as a sign of corrupted state"],"tags":["random-collision","site-creation","zeronet"],"backgroundTag":"site-address-collision","analyzedSha":"454c0b2e7e000fda7000cba49027541fbf327b96","analyzedAt":"2026-09-02T19:46:57.278Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}