nautechsystems/nautilus_trader · critical
No session token after login
Error message
No session token after login
What it means
After a successful HTTP login, the data client fetches the cached session token from the HTTP client to authenticate stream connections. If session_token() returns None, login claimed success but no token was stored — an invariant violation indicating the login did not actually yield a session token.
Solutions
- Log the raw login response/status from the HTTP client to see why no token was produced
- Verify Betfair credentials and App Key are valid and the account is active
- Check for a concurrent disconnect()/token-clear racing the connect; serialize connect/disconnect
- Retry connect — a transient bad login response usually resolves; if persistent, it is a credentials/endpoint problem
Defensive patterns
Strategy: retry
Validate before calling
// after connect succeeds, confirm token presence before relying on streams
if client.session_token().await.is_none() {
log::error!("Betfair login produced no session token; re-authenticating");
} Try / catch
match client.connect().await {
Err(e) if e.to_string().contains("No session token after login") => {
// token missing: re-authenticate once, then surface credentials problem
tokio::time::sleep(Duration::from_secs(2)).await;
client.connect().await.map_err(|e| { log::error!("retry failed: {e:#}"); e })
}
other => other,
} Prevention
- Verify Betfair credentials/App Key validity periodically
- Avoid clearing http client state between login and stream setup
- Serialize connect/disconnect to prevent token-clear races
- Log the raw login response when token absence is suspected
When it happens
Trigger: connect() -> after provider.load_all and instrument caching, self.http_client.session_token().await returns None, so ok_or_else raises this error. Happens when the Betfair login response lacked a session token (token field absent/empty) or the client state was reset between login and this call.
Common situations: Betfair API returning an unexpected login response shape; expired/revoked credentials that still pass a partial handshake; a race where disconnect cleared the token during connect; misconfigured App Key that authenticates but returns no session.
Related errors
- No session token after login
- No session token for cricket stream
- No session token for race stream
- {e}
- {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/56ac2fba9e05118d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/betfair/src/data.rs:780
self.instruments.rcu(|m| {
for inst in &loaded {
m.insert(inst.id(), inst.clone());
}
});
for inst in &loaded {
if let Err(e) = self.data_sender.send(DataEvent::Instrument(inst.clone())) {
log::warn!("Failed to send instrument: {e}");
}
}
log::debug!("Cached {} instruments for {}", loaded.len(), self.client_id,);
let session_token = self
.http_client
.session_token()
.await
.ok_or_else(|| anyhow::anyhow!("No session token after login"))?;
let (reconnect_tx, mut reconnect_rx) = tokio::sync::mpsc::unbounded_channel();
let handler = Self::create_stream_handler(
self.data_sender.clone(),
Arc::clone(&self.instruments),
self.currency,
self.provider.min_notional(),
reconnect_tx.clone(),
self.clock,
);
let state_sink = self.socket_control.as_ref().map(SocketControl::sink);
let stream_client = BetfairStreamClient::connect_with_state_sink(
&self.credential,
session_token,
handler,
self.stream_config.clone(),View on GitHub (pinned to 18893faf8b)