You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用代理时NodeJS报Request path contains unescaped characters错误

Fixing "Request path contains unescaped characters" with request-promise on Ubuntu 18.04

Hey there, let's tackle this frustrating proxy issue you're hitting! Based on the details you shared—working requests without proxy, failing with any proxy, and ruling out encoding/URL/provider/server issues—the problem likely stems from how the older version of request-promise (and its underlying request library) parses proxy URLs with authentication. Here are actionable fixes to try:

1. Manually escape special characters in your proxy URL

If your proxy password (or username) contains special characters like @, :, /, or %, these can break URL parsing in older request versions. Even if you think you've checked encoding, double-check by replacing these characters with their URL-encoded equivalents:

  • @ → %40
  • : → %3A
  • / → %2F
  • % → %25

For example, if your proxy URL is http://user:pass@word@proxyserver:8080, rewrite it to:

http://user:pass%40word@proxyserver:8080

2. Use the proxy configuration object instead of a URL string

Older versions of request handle proxy authentication more reliably when you pass a configuration object instead of a raw URL. This avoids any parsing issues with special characters in credentials. Modify your opts like this:

{
  url: "https://google.com",
  proxy: {
    host: "proxyserver",
    port: 8080, // Replace with your actual proxy port
    auth: {
      user: "your-proxy-username",
      pass: "your-proxy-password"
    }
  }
}

Update your makeRequest function to accept this object format, and the request library will handle the authentication encoding correctly under the hood.

3. Upgrade compatible dependencies (if possible)

You're using Node.js v8.10.0 and request-promise v4.2.2—both are quite old. While Node.js 8 is end-of-life, you can still upgrade to the latest compatible versions of request and request-promise that support Node.js 8. This might fix the URL parsing bug entirely:

npm install request@^2.88.2 request-promise@^4.2.6

These versions are known to work with Node.js 8 and include fixes for proxy URL handling.

Why this happens

When using a proxy, the request library parses the proxy URL to extract host, port, and authentication details. Older versions have a bug where special characters in the authentication segment (username/password) cause incorrect path parsing, triggering the "unescaped characters" error. When not using a proxy, this parsing step is skipped, so your requests work as expected.

内容的提问来源于stack exchange,提问作者user8979341

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:50:19