crowdsecurity/crowdsec · error
could not create request: %w
Error message
could not create request: %w
What it means
Returned by refreshJwtToken when http.NewRequestWithContext rejects the login URL built from the transport's URL and version prefix for the POST to /watchers/login — typically a malformed or unparsable API URL configuration. Wraps the request-construction error.
Source
Thrown at pkg/apiclient/auth_jwt.go:75
Password: t.Password,
Scenarios: t.Scenarios,
}
/*
we don't use the main client, so let's build the body
*/
var buf io.ReadWriter = &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
err = enc.Encode(auth)
if err != nil {
return fmt.Errorf("could not encode jwt auth body: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s%s/watchers/login", t.URL, t.VersionPrefix), buf)
if err != nil {
return fmt.Errorf("could not create request: %w", err)
}
req.Header.Add("Content-Type", "application/json")
transport := t.Transport
if transport == nil {
transport = http.DefaultTransport
}
client := &http.Client{
Transport: &retryRoundTripper{
next: transport,
maxAttempts: 5,
withBackOff: true,
retryStatusCodes: []int{http.StatusTooManyRequests, http.StatusServiceUnavailable, http.StatusGatewayTimeout, http.StatusInternalServerError},
},
}
View on GitHub (pinned to 909b515798)
Solutions
- Fix the api_url in the crowdsec config (must be a valid URL)
- Check for control characters or malformed scheme in the configured URL
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at pkg/apiclient/auth_jwt.go:75 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/bf6c73a7c2ac616a.
Report an issue: GitHub.