{"record":{"id":"736b05a37237379f","repo":"iawia002/lux","slug":"douyin-ttwid-request-failed","errorCode":null,"errorMessage":"douyin ttwid request failed","messagePattern":"douyin ttwid request failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extractors/douyin/douyin.go","lineNumber":211,"sourceCode":"\t\t\"service\":       \"www.ixigua.com\",\n\t\t\"migrate_info\":  map[string]string{\"ticket\": \"\", \"source\": \"node\"},\n\t}\n\tbytes, err := json.Marshal(body)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tpayload := strings.NewReader(string(bytes))\n\tresp, err := request.Request(http.MethodPost, \"https://ttwid.bytedance.com/ttwid/union/register/\", payload, nil)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdefer resp.Body.Close() // nolint\n\tcookie := resp.Header.Get(\"Set-Cookie\")\n\tre := regexp.MustCompile(`ttwid=([^;]+)`)\n\tif match := re.FindStringSubmatch(cookie); match != nil {\n\t\treturn match[1], nil\n\t}\n\treturn \"\", errors.New(\"douyin ttwid request failed\")\n}\n","sourceCodeStart":193,"sourceCodeEnd":213,"githubUrl":"https://github.com/iawia002/lux/blob/dd00f6d258d80b6684a0b9402d7124e5c18ef42f/extractors/douyin/douyin.go#L193-L213","documentation":"To call douyin's web API, the extractor registers a ttwid cookie by POSTing a region payload to ttwid.bytedance.com/ttwid/union/register/. The HTTP call succeeded, but no ttwid=... value could be extracted from the Set-Cookie header, so cookie minting failed and extraction aborts. It is a header-content failure, not a transport error.","triggerScenarios":"Bytedance returning an error body instead of issuing the cookie (payload/region mismatch); proxies or corporate MITM stripping Set-Cookie; a transient server-side change in cookie issuance.","commonSituations":"Running from cloud/datacenter IPs that bytedance flags; header-mangling middleboxes; temporary endpoint instability.","solutions":["Retry — issuance is frequently transient.","Log the response status and Set-Cookie header to confirm the endpoint itself answered rather than a proxy error page.","Run from a residential IP or a different network.","If the register contract changed, update the URL/payload in createCookie."],"exampleFix":"// before\ncookie, err := createCookie()\n// after — retry the mint a few times before giving up\nvar cookie string\nfor i := 0; i < 3; i++ {\n\tcookie, err = createCookie()\n\tif err == nil {\n\t\tbreak\n\t}\n\ttime.Sleep(time.Second * time.Duration(i+1))\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"Bounded retry: call createCookie up to 3 times with short backoff; between attempts log the HTTP status and Set-Cookie presence so a 4xx or a header-stripping proxy is visible. Abort the douyin batch only after all attempts fail.","preventionTips":["Avoid datacenter egress IPs for douyin — they are the main trigger","Cache the minted ttwid cookie for the whole batch instead of minting per URL","Log Set-Cookie headers on failure to distinguish server-side refusal from proxy interference"],"tags":["douyin","cookie","network","anti-bot"],"backgroundTag":null,"analyzedSha":"dd00f6d258d80b6684a0b9402d7124e5c18ef42f","analyzedAt":"2026-08-15T16:57:31.080Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}