chenhg5/cc-connect · error
wecom: invalid api_base_url %q: must be a valid http(s) URL
Error message
wecom: invalid api_base_url %q: must be a valid http(s) URL
What it means
When api_base_url is set in the options, New() parses it and requires scheme http or https plus a non-empty host. Empty or missing api_base_url falls back to the official WeCom API base URL, but a present-but-malformed value aborts construction. This lets deployments point the platform at a proxy or self-hosted gateway while rejecting typos early.
Source
Thrown at platform/wecom/wecom.go:157
return nil, fmt.Errorf("wecom: invalid callback_aes_key: %w", err)
}
port, _ := opts["port"].(string)
if port == "" {
port = "8081"
}
path, _ := opts["callback_path"].(string)
if path == "" {
path = "/wecom/callback"
}
apiBaseURL, _ := opts["api_base_url"].(string)
apiBaseURL = strings.TrimRight(strings.TrimSpace(apiBaseURL), "/")
if apiBaseURL == "" {
apiBaseURL = defaultAPIBaseURL
} else {
parsed, err := url.Parse(apiBaseURL)
if err != nil || (parsed.Scheme != "https" && parsed.Scheme != "http") || parsed.Host == "" {
return nil, fmt.Errorf("wecom: invalid api_base_url %q: must be a valid http(s) URL", apiBaseURL)
}
}
transport := &http.Transport{
MaxIdleConns: 2,
MaxIdleConnsPerHost: 1,
IdleConnTimeout: 10 * time.Second,
}
if proxyURL, _ := opts["proxy"].(string); proxyURL != "" {
u, err := url.Parse(proxyURL)
if err != nil {
return nil, fmt.Errorf("wecom: invalid proxy URL %q: %w", proxyURL, err)
}
proxyUser, _ := opts["proxy_username"].(string)
proxyPass, _ := opts["proxy_password"].(string)
if proxyUser != "" {
u.User = url.UserPassword(proxyUser, proxyPass)
}View on GitHub (pinned to 4000b2338a)
Solutions
- Prefix the value with https:// (e.g. https://qyapi.weixin.qq.com) and ensure a hostname is present
- Remove the api_base_url option entirely to use the default official endpoint
- Validate the URL with url.Parse in a quick script before putting it in config
- Check for template/variable expansion mistakes that leave placeholder text in the value
Example fix
// before "api_base_url": "qyapi.weixin.qq.com" // no scheme -> invalid api_base_url // after "api_base_url": "https://qyapi.weixin.qq.com"
Defensive patterns
Strategy: validation
Validate before calling
u, _ := opts["api_base_url"].(string)
if u != "" {
if parsed, err := url.Parse(strings.TrimSpace(u)); err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") || parsed.Host == "" {
return fmt.Errorf("api_base_url %q is not a valid http(s) URL", u)
}
} Prevention
- Always include the scheme (https://) in base URLs
- Leave api_base_url unset unless pointing at a gateway/proxy
- Validate URLs in config linting before deployment
- Watch for template placeholders that don't expand
When it happens
Trigger: Setting api_base_url to a value like "qyapi.weixin.qq.com" (no scheme), "ftp://host", "://host", or any string that url.Parse rejects, fails to produce scheme http/https, or yields an empty Host.
Common situations: Typing the domain without https://; a corporate gateway URL with a typo or trailing path issues; config templating that leaves an invalid placeholder; pointing at a local mock server with a wrong scheme like localhost:8080 without http://.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- wecom-ws: bot_id and bot_secret are required for websocket m
- wecom: callback_token and callback_aes_key are required
- wecom: invalid callback_aes_key: %w
- wecom: invalid proxy URL %q: %w
- invalid remote image URL
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/a13703333be02830.
Report an issue: GitHub.