nautechsystems/nautilus_trader · error · anyhow::Error
Failed to create HTTP client: {e}
Error message
Failed to create HTTP client: {e} What it means
The authenticated branch of the data-client factory: building the underlying HTTP stack (AxHttpClient::with_credentials -> HttpClient::new with headers, rate-limiter quotas, timeout and optional proxy) returned Err, re-wrapped as AxHttpError::NetworkError("Failed to create HTTP client: ...") and surfaced with this anyhow context. Construction-time failures are local, not venue responses: typically an invalid proxy_url, a TLS/connector initialization failure, or a misbuilt client runtime.
Source
Thrown at crates/adapters/architect_ax/src/factories.rs:118
let client_id = ClientId::from(name);
let http_client = if ax_config.has_api_credentials() {
let credential =
Credential::resolve(ax_config.api_key.clone(), ax_config.api_secret.clone())
.ok_or_else(|| anyhow::anyhow!("API credentials not configured"))?;
AxHttpClient::with_credentials(
credential.api_key().to_string(),
credential.api_secret().to_string(),
Some(ax_config.http_base_url()),
None, // orders_base_url
ax_config.http_timeout_secs,
ax_config.max_retries,
ax_config.retry_delay_initial_ms,
ax_config.retry_delay_max_ms,
ax_config.proxy_url.clone(),
)
.map_err(|e| anyhow::anyhow!("Failed to create HTTP client: {e}"))?
} else {
AxHttpClient::new(
Some(ax_config.http_base_url()),
None, // orders_base_url
ax_config.http_timeout_secs,
ax_config.max_retries,
ax_config.retry_delay_initial_ms,
ax_config.retry_delay_max_ms,
ax_config.proxy_url.clone(),
)
.map_err(|e| anyhow::anyhow!("Failed to create HTTP client: {e}"))?
};
let ws_url = ax_config.ws_public_url();
// Token set during connect
let ws_client = AxMdWebSocketClient::without_auth(
ws_url,View on GitHub (pinned to a4b06ed870)
Solutions
- Check the inner {e}: 'proxy' errors -> fix/remove proxy_url in the config; TLS errors -> check build features and CA store
- Retry with proxy_url: None to isolate whether the proxy is the cause
- Validate the proxy URL parses (reqwest::Proxy::all) before passing it into config
- Confirm the same config works in a plain environment (no proxy env vars like HTTPS_PROXY leaking in)
Example fix
// before
let cfg = AxDataClientConfig::builder()
.proxy_url(Some("localhost:8080".into())) // missing scheme -> client build fails
.build()?;
// after
let cfg = AxDataClientConfig::builder()
.proxy_url(Some("http://localhost:8080".into()))
.build()?; Defensive patterns
Strategy: validation
Validate before calling
// Validate the proxy URL before handing it to the config
if let Some(proxy) = &config.proxy_url {
reqwest::Proxy::all(proxy.as_str())
.with_context(|| format!("invalid proxy_url: {proxy}"))?;
} Try / catch
match AxDataClientFactory.create(...) {
Err(e) if e.to_string().contains("Failed to create HTTP client") => {
log::error!("local HTTP stack init failed: {e:#}"); // do not retry unchanged config
Err(e)
}
r => r,
} Prevention
- Always include the scheme in proxy_url (http:// or https:// or socks5://)
- Clear stray HTTPS_PROXY/HTTP_PROXY/ALL_PROXY env vars in deployment manifests unless intended
- Smoke-test client construction in CI with and without proxy configured
When it happens
Trigger: AxDataClientConfig with proxy_url set to a malformed URL or unreachable proxy scheme; TLS backend problems in the build (missing rustls/native-tls features); exotic runtime configurations where the HTTP connector cannot initialize. Happens with valid credentials - it fails before any request is sent.
Common situations: Corporate-proxy deployments where proxy_url was typo'd (missing scheme, bad port); hardened containers missing CA bundles; feature-flag mismatches after editing the crate's Cargo features.
Related errors
- Invalid config type for AxDataClientFactory. Expected AxData
- Invalid config type for AxExecutionClientFactory. Expected A
- Authentication failed: {e}
- Invalid order side: {e}
- Instrument {instrument_id} not found in cache
AI-assisted analysis of nautechsystems/nautilus_trader@a4b06ed870 (2026-08-16).
Data as JSON: /api/errors/a5919561e965bbe5.
Report an issue: GitHub.