{"record":{"id":"4f22233ab69a27cf","repo":"XX-net/XX-Net","slug":"dns-server-s-domain-s-fail-t-f","errorCode":null,"errorMessage":"DNS server:%s domain:%s fail t:%f","messagePattern":"DNS server:(.+?) domain:(.+?) fail t:(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/smart_router/local/dns_query.py","lineNumber":542,"sourceCode":"            }, timeout=self.timeout)\n        else:\n            return simple_http_client.Client(timeout=self.timeout)\n\n    @property\n    def server(self):\n        return random.choice(self.other_servers)\n\n    def query_json(self, domain, dns_type=1):\n        try:\n            t0 = time.time()\n            client = self.get_connection()\n\n            url = self.server + \"?name=\" + domain + \"&type=A\" # type need to map to Text.\n            r = client.request(\"GET\", url, headers={\"accept\": \"application/dns-json\"})\n            t2 = time.time()\n            ips = []\n            if not r:\n                xlog.warn(\"DNS server:%s domain:%s fail t:%f\", self.server, domain,  t2 - t0)\n                return ips\n\n            t = utils.to_str(r.text)\n\n            data = json.loads(t)\n            for answer in data[\"Answer\"]:\n                ips.append(answer[\"data\"])\n\n            self.connections.append([client, time.time()])\n\n            xlog.debug(\"DNS server:%s query:%s return %s t:%f\", self.server, domain, ips, t2 - t0)\n            return ips\n        except Exception as e:\n            xlog.warn(\"DNSOverHttpsQuery query fail:%r\", e)\n            return []\n\n    def query(self, domain, dns_type=1, url=None):\n        t0 = time.time()","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/smart_router/local/dns_query.py#L524-L560","documentation":"query_json() in the DoH client sends a GET request to the resolver's JSON API (RFC 8484 JSON style, e.g. Cloudflare/Google) and the HTTP client returned a falsy/None response. The request failed before any HTTP data was processed (connection error, blocked request, or the client's internal failure), so an empty IP list is returned.","triggerScenarios":"Calling query() on DnsOverHttpsQuery when the HTTPS request to self.server fails to connect or is rejected — DNS URL wrong, proxy required but unavailable, TLS failure, or the endpoint blocked/returning nothing the client accepts.","commonSituations":"DoH endpoint blocked or hijacked on the network, wrong self.server URL (must support ?name=&type=A JSON API), corporate TLS-inspection proxies breaking the request, no internet connectivity, GFW-style blocking of well-known DoH providers.","solutions":["Verify the DoH endpoint manually: 'curl -H 'accept: application/dns-json' 'https://1.1.1.1/dns-query?name=example.com&type=A''","Ensure self.server points at a JSON-capable DoH resolver (Cloudflare, Google) and not a pure RFC8484 wire-format endpoint","Check proxy/TLS settings of the HTTP client used by this module","Retry with backoff — transient HTTPS failures are common; consider a second DoH provider as fallback"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"import requests\ndef doh_endpoint_ok(server):\n    try:\n        r = requests.get(server, params={'name': 'example.com', 'type': 'A'},\n                         headers={'accept': 'application/dns-json'}, timeout=5)\n        return r.status_code == 200 and 'Answer' in r.json()\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"for server in doh_servers:  # rotate providers\n    ips = doh_client.query(domain)\n    if ips:\n        break","preventionTips":["Configure multiple DoH providers and rotate on empty responses","Verify the endpoint supports the JSON API, not just RFC 8484 wire format","Always check query() return for emptiness before use; never assume success"],"tags":["dns","doh","https","http-client","request-failed"],"backgroundTag":"https-request-failed","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}