{"record":{"id":"ebadee167c65921d","repo":"tonhowtf/omniget","slug":"instagram-gql-retornou-http","errorCode":null,"errorMessage":"Instagram GQL retornou HTTP {}","messagePattern":"Instagram GQL retornou HTTP (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/platforms/instagram.rs","lineNumber":423,"sourceCode":"            .header(\"Content-Type\", \"application/x-www-form-urlencoded\")\n            .header(\"Sec-Fetch-Dest\", \"empty\")\n            .header(\"Sec-Fetch-Mode\", \"cors\")\n            .header(\"Sec-Fetch-Site\", \"same-origin\")\n            .header(\"X-Requested-With\", \"XMLHttpRequest\")\n            .header(\"x-ig-app-id\", &params.app_id)\n            .header(\"X-FB-LSD\", &params.lsd_token)\n            .header(\"X-CSRFToken\", &params.csrf_token)\n            .header(\"X-FB-Friendly-Name\", \"PolarisPostActionLoadPostQueryQuery\")\n            .header(\"x-asbd-id\", \"129477\")\n            .header(\"X-Bloks-Version-Id\", &params.bloks_version_id)\n            .header(\"Referer\", \"https://www.instagram.com/\")\n            .header(\"Cookie\", &anon_cookie)\n            .body(body)\n            .send()\n            .await?;\n\n        if !response.status().is_success() {\n            return Err(anyhow!(\"Instagram GQL retornou HTTP {}\", response.status()));\n        }\n\n        let json: serde_json::Value = response.json().await?;\n\n        let data = json\n            .get(\"data\")\n            .ok_or_else(|| anyhow!(\"Resposta GQL sem data\"))?;\n\n        let media = data\n            .get(\"xdt_shortcode_media\")\n            .or_else(|| data.get(\"shortcode_media\"));\n\n        match media {\n            Some(m) if !m.is_null() => Ok(m.clone()),\n            _ => Err(anyhow!(\"Post not found via GQL\")),\n        }\n    }\n","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/instagram.rs#L405-L441","documentation":"request_gql posts to Instagram's GraphQL endpoint with an anonymous cookie; any non-2xx HTTP status aborts with this error embedding the status code. It means the transport-level request succeeded but Instagram rejected it at HTTP level rather than returning a JSON payload.","triggerScenarios":"request_gql receives a response whose status().is_success() is false — e.g. 401/403 for blocked/absent anonymous cookie, 429 rate limiting, 5xx from Instagram, or a 404 after endpoint changes.","commonSituations":"Sending GQL queries too fast and getting 429; Instagram rotating endpoint requirements and returning 403 for missing headers (x-ig-app-id, csrf); anonymous cookie stale/expired; scraping from cloud IPs that Instagram blocks outright.","solutions":["Log the embedded status code: 429 → back off and retry with exponential delay; 401/403 → refresh the anonymous cookie and required headers (x-ig-app-id, X-CSRFToken).","Re-fetch a fresh anonymous cookie before retrying — stale cookies are a common cause of 403s.","Add per-request jitter/throttling to stay under Instagram's rate limits.","If 403 persists, update the client headers to match the current Instagram web app; check the library for newer versions."],"exampleFix":"// before\nlet response = self.client.post(&gql_url).header(\"Cookie\", &anon_cookie).body(body).send().await?;\nif !response.status().is_success() {\n    return Err(anyhow!(\"Instagram GQL retornou HTTP {}\", response.status()));\n}\n// after\nlet response = self.client.post(&gql_url).header(\"Cookie\", &anon_cookie).body(body).send().await?;\nmatch response.status() {\n    s if s.as_u16() == 429 => {\n        tokio::time::sleep(Duration::from_secs(30)).await;\n        return self.request_gql(shortcode).await; // retry once after backoff\n    }\n    s if !s.is_success() => anyhow::bail!(\"Instagram GQL retornou HTTP {}\", s),\n    _ => {}\n}","handlingStrategy":"retry","validationCode":"// Before the GQL call, confirm you have a fresh anonymous cookie:\n// let anon_cookie = fetch_anon_cookie().await?;\n// anyhow::ensure!(!anon_cookie.is_empty(), \"missing Instagram anonymous cookie\");","typeGuard":null,"tryCatchPattern":"async fn gql_with_retry(client: &Client, body: String, attempts: u32) -> anyhow::Result<Response> {\n    for i in 0..attempts {\n        let resp = client.post(GQL_URL).header(\"Cookie\", &anon_cookie).body(body.clone()).send().await?;\n        match resp.status().as_u16() {\n            200 => return Ok(resp),\n            429 => tokio::time::sleep(Duration::from_secs(5 * 2u64.pow(i))).await,\n            401 | 403 => refresh_anon_cookie().await?,\n            s => anyhow::bail!(\"Instagram GQL retornou HTTP {}\", s),\n        }\n    }\n    anyhow::bail!(\"gql retries exhausted\")\n}","preventionTips":["Throttle GQL requests with jittered delays to avoid 429s.","Refresh anonymous cookies regularly and on 401/403.","Send the full header set the web app uses (x-ig-app-id, X-CSRFToken, UA).","Distinguish retryable (429/5xx) from fatal (401/403) statuses in your error handling."],"tags":["instagram","http","rate-limit","graphql","rust"],"backgroundTag":"http-error-response","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}