{"id":"e0075b1f13db7d39","repo":"seanmonstar/reqwest","slug":"parsed-url-is-not-a-valid-uri","errorCode":null,"errorMessage":"Parsed Url is not a valid Uri","messagePattern":"Parsed Url is not a valid Uri","errorType":"validation","errorClass":"reqwest::Error","httpStatus":null,"severity":"error","filePath":"src/error.rs","lineNumber":392,"sourceCode":"        Kind::Status(\n            status,\n            #[cfg(not(all(\n                target_arch = \"wasm32\",\n                any(target_os = \"unknown\", target_os = \"none\")\n            )))]\n            reason,\n        ),\n        None::<Error>,\n    )\n    .with_url(url)\n}\n\npub(crate) fn url_bad_scheme(url: Url) -> Error {\n    Error::new(Kind::Builder, Some(BadScheme)).with_url(url)\n}\n\npub(crate) fn url_invalid_uri(url: Url) -> Error {\n    Error::new(Kind::Builder, Some(\"Parsed Url is not a valid Uri\")).with_url(url)\n}\n\nif_wasm! {\n    pub(crate) fn wasm(js_val: wasm_bindgen::JsValue) -> BoxError {\n        format!(\"{js_val:?}\").into()\n    }\n}\n\npub(crate) fn upgrade<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Upgrade, Some(e))\n}\n\n// io::Error helpers\n\n#[allow(unused)]\npub(crate) fn decode_io(e: io::Error) -> Error {\n    if e.get_ref().map(|r| r.is::<Error>()).unwrap_or(false) {\n        *e.into_inner()","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/seanmonstar/reqwest/blob/17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d/src/error.rs#L374-L410","documentation":"Constructed by `error::url_invalid_uri` (error.rs:391-393) as `Kind::Builder`. It fires when a URL parses fine as a `url::Url` but then fails to re-parse as an `http::Uri` in `try_uri` (into_url.rs:77-81, client.rs:2639-2641). The `Url` and `Uri` grammars differ, so a valid URL can still be unusable as an HTTP target.","triggerScenarios":"URLs containing characters or structures legal to `url` but rejected by `http::Uri` — e.g. certain encoded characters in the authority, non-ASCII host without proper handling, or overly long components exceeding `Uri` limits.","commonSituations":"Internationalized domain names handled differently between `url` and `http`; exotic percent-encoding in userinfo; copied URL with unusual characters that `Url::parse` accepts but `hyper`/`http` rejects.","solutions":["Inspect the exact URL string from `e.url()` and re-encode/normalize it (e.g. via `url::Url` normalization or punycode the host).","Simplify the URL — drop unusual userinfo, percent-encode path/query properly — and retry.","If reproducible, file the failing input against `http`/`hyper` with the rejected substring."],"exampleFix":"// before\nlet r = client.get(raw_url).send().await?; // 'Parsed Url is not a valid Uri'\n\n// after\nlet parsed = url::Url::parse(&raw_url)?;\n// re-encode host to ASCII / normalize, then send the canonical form\nlet canon = parsed.to_string();\nlet r = client.get(canon).send().await?;","handlingStrategy":"validation","validationCode":"fn normalize_for_http(raw: &str) -> anyhow::Result<String> {\n    let u = url::Url::parse(raw)?;\n    let s = u.to_string();\n    s.parse::<http::Uri>().map_err(|e| anyhow!(\"not a valid Uri: {e}\"))?;\n    Ok(s)\n}\n","typeGuard":"fn is_invalid_uri(e: &reqwest::Error) -> bool {\n    e.is_builder() && e.source().map(|s| s.to_string() == \"Parsed Url is not a valid Uri\").unwrap_or(false)\n}\n","tryCatchPattern":"let url = normalize_for_http(&raw).unwrap_or_else(|_| {\n    log::warn!(\"url rejected by http::Uri, falling back to base\");\n    base_url.clone()\n});\nlet resp = client.get(url).send().await?;","preventionTips":["Round-trip user URLs through url::Url and re-encode non-ASCII hosts (punycode).","Avoid exotic characters in userinfo/path; percent-encode properly.","Validate against http::Uri at the boundary if your service accepts arbitrary URLs."],"tags":["url","uri","builder","parsing"],"analyzedSha":"17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d","analyzedAt":"2026-08-06T01:23:05.134Z","schemaVersion":2}