yikart/AiToEarn · error · Error
代理地址不合法
Error message
代理地址不合法
What it means
requestNet validates any proxy string passed in its options. The proxy string is parsed with parseProxyString and the resulting ipAndPort must match the ipv4Regular IPv4 regex; if parsing fails (returns false) or the address is not a valid IPv4:port, this Error is thrown. The library only supports IPv4 proxy addresses, not hostnames or IPv6.
Source
Thrown at project/aitoearn-electron/electron/plat/requestNet.ts:46
headers,
body,
method,
url,
isFile,
formData,
isReqFile,
proxy,
}: IRequestNetParams): Promise<IRequestNetResult<T>> => {
let customSession: Session;
let proxyInfo: ProxyInfo | false;
return new Promise(async (resolve, reject) => {
try {
// 如果传入了代理配置,动态设置代理
if (proxy) {
// 解析代理信息
proxyInfo = parseProxyString(proxy);
if (proxyInfo === false || !ipv4Regular.test(proxyInfo.ipAndPort))
throw new Error('代理地址不合法');
customSession = session.fromPartition(
`persist:proxy-session-${Date.now()}`,
);
const proxyUrl = `${proxyInfo.protocol}://${proxyInfo.ipAndPort}`;
const proxyRules = `http=${proxyUrl};https=${proxyUrl}`;
console.log(proxyRules);
await customSession.setProxy({
proxyRules,
});
headers = {
...(headers ? headers : {}),
...(proxy
? {
'x-forwarded-for': proxyInfo.ipAndPort,
}
: {}),
};View on GitHub (pinned to d3aa8bea5b)
Solutions
- Use a numeric IPv4 address with port, e.g. '127.0.0.1:7890' or '192.168.1.10:8080'.
- Check the string format parseProxyString expects (protocol + ip:port, optionally user:pass) and match it exactly.
- Remove the proxy option entirely if no proxy is needed — validation only runs when proxy is truthy.
- Pre-validate the proxy with the ipv4Regular regex before passing it to requestNet.
Example fix
// before
await requestNet({ url, proxy: 'http://proxy.corp.local:8080' });
// after
const proxy = 'http://10.0.0.8:8080'; // must be IPv4 ip:port
if (!ipv4Regular.test(proxy)) throw new Error('proxy must be ipv4:port');
await requestNet({ url, proxy }); Defensive patterns
Strategy: validation
Validate before calling
import { ipv4Regular } from './commont/regular';
function isProxyValid(proxy?: string): boolean {
if (!proxy) return true; // no proxy is fine
const m = proxy.match(/^(\w+:\/\/)?([^/?]+)$/);
return !!m && ipv4Regular.test(m[2]);
}
if (!isProxyValid(proxy)) throw new Error('proxy must be ipv4:port'); Type guard
function parseProxySafe(proxy: string): ProxyInfo | null {
const info = parseProxyString(proxy);
return info === false ? null : info;
} Try / catch
try {
await requestNet({ url, proxy });
} catch (e) {
if (e.message === '代理地址不合法') {
// prompt user to enter a valid ipv4:port proxy
}
} Prevention
- Always store proxies as ipv4:port, never hostnames or URLs
- Pre-validate with the ipv4Regular regex at config entry (UI/form layer)
- Omit the proxy field entirely when no proxy is needed
- Document that IPv6 and DNS-name proxies are unsupported
When it happens
Trigger: Calling requestNet (or any platform service that forwards a proxy option, e.g. Douyin/Shipinhao publish flows) with proxy set to a malformed string like 'http=proxy.com:8080' (hostname), an IPv6 address, a missing port, or an unparseable format.
Common situations: Users entering a proxy hostname (e.g. proxy.example.com:8080) instead of an IP, copying a proxy URL with scheme/path into the ip:port field, IPv6 proxies, or empty/garbage values in proxy config UI.
Related errors
- InvalidModel
- InvalidModel
- image aspectRatio cannot be converted to a supported size
- No subtitle entries in response
- No response from Gemini
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/a4d8cb0561f0a85d.
Report an issue: GitHub.