fish2018/pansou · error

不支持的代理协议

Error message

不支持的代理协议: %s

What it means

applyProxy only supports socks5/socks5h and http/https proxy schemes; any other scheme reaches the default branch and produces this error naming the unsupported scheme. It is a whitelist validation so misconfigured proxies fail fast instead of silently being ignored.

Solutions

  1. Change the proxy scheme to a supported one: 'http', 'https', 'socks5', or 'socks5h'.
  2. If you have a SOCKS4 proxy, switch to a SOCKS5 or HTTP endpoint (most proxy servers offer both).
  3. Fully qualify bare host:port values as 'http://host:port' so the scheme parses correctly.
  4. Check the error's %s value to see what scheme was actually parsed — it often reveals a malformed URL.

Example fix

// before
client, err := NewHTTPClient(WithProxy("socks4://127.0.0.1:1080"))

// after
client, err := NewHTTPClient(WithProxy("socks5://127.0.0.1:1080"))
Defensive patterns

Strategy: validation

Validate before calling

allowed := map[string]bool{"http": true, "https": true, "socks5": true, "socks5h": true}
if u, err := url.Parse(cfg.Proxy); err == nil && !allowed[strings.ToLower(u.Scheme)] {
    return fmt.Errorf("unsupported proxy scheme %q", u.Scheme)
}

Try / catch

if err := NewHTTPClient(WithProxy(cfg.Proxy)); err != nil {
    if strings.Contains(err.Error(), "不支持的代理协议") {
        // switch config to http/https/socks5 scheme
    }
    return err
}

Prevention

When it happens

Trigger: NewHTTPClient called with a proxy using a scheme like 'ftp://', 'socks4://', 'socks://', or a garbage scheme such as '127.0.0.1' alone (where the host part becomes the scheme after parsing).

Common situations: Users configuring SOCKS4 proxies the library does not support; bare 'host:port' values where 'host' is misparsed as a scheme; typos like 'htt://' or 'socks5:// ' variants; copying proxy settings from tools that accept more schemes.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07). Data as JSON: /api/errors/dd309747e7d88ba8. Report an issue: GitHub.

Appendix: source

Thrown at util/http_util.go:111

			clone := *proxyURL
			clone.Scheme = "socks5"
			proxyURL = &clone
		}

		// 创建SOCKS5代理拨号器
		dialer, err := proxy.FromURL(proxyURL, proxy.Direct)
		if err != nil {
			return fmt.Errorf("SOCKS5代理初始化失败: %w", err)
		}

		transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
			return dialer.Dial(network, addr)
		}
	case "http", "https":
		// HTTP/HTTPS代理
		transport.Proxy = http.ProxyURL(proxyURL)
	default:
		return fmt.Errorf("不支持的代理协议: %s", proxyURL.Scheme)
	}

	return nil
}

// GetHTTPClient 获取HTTP客户端
func GetHTTPClient() *http.Client {
	if httpClient == nil {
		InitHTTPClient()
	}
	return httpClient
}

// FetchHTML 获取HTML内容
func FetchHTML(targetURL string) (string, error) {
	// 使用优化后的HTTP客户端
	client := GetHTTPClient()

View on GitHub (pinned to beaa561337)