Skip to content

enhancement: auto-prepend http:// scheme to http_proxy config for httpx compatibility #8292

@ydicucu

Description

@ydicucu

enhancement: auto-prepend http:// scheme to http_proxy config for httpx compatibility

Background

AstrBot supports configuring an HTTP proxy via the http_proxy field in cmd_config.json. The value is then set as an environment variable in core_lifecycle.py:

os.environ["http_proxy"] = proxy_config

This value is consumed by various libraries, notably httpx (which is used internally by the OpenAI SDK and many AstrBot provider modules).

Problem

When a user configures the proxy without a URL scheme (e.g., 127.0.0.1:7890 instead of http://127.0.0.1:7890), the following issues arise:

  • curl and the requests library handle this gracefully
  • httpx throws ValueError: Unknown scheme for proxy URL, breaking all httpx-dependent features (Whisper STT, TTS, OpenAI API calls, etc.)

This creates an inconsistent user experience, as the same proxy value works with some tools but silently breaks others.

Current state

The WebUI config schema does include a hint explaining the expected format (http://127.0.0.1:7890). However:

  • Users who edit cmd_config.json directly never see this hint
  • There is no code-level validation or defensive handling in core_lifecycle.py
  • The error message (ValueError: Unknown scheme for proxy URL) is opaque to non-technical users

Suggested fix

In core_lifecycle.py, before setting the proxy environment variables, add a simple scheme auto-completion:

if "://" not in proxy_config:
    proxy_config = "http://" + proxy_config

This is a minimal, zero-side-effect change that makes the configuration more robust without breaking existing setups.

Additional context

  • AstrBot version: 4.25.1+
  • OS: Linux
  • No existing issues found on this topic
  • The fix has been tested locally and works as expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backend

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions