npm 遇到 E407 代理验证错误但代理 wget 正常

查看 42|回复 5
作者:zhiqiang   
不知道有人碰到没,头大。
系统:unbuntu 24.04 (刚升级的,不知道和这个有没有关系),node/npm 都是 apt 安装的,node 版本 v18.19.1 ,npm 版本 9.2.0 。
npm 无论安装什么包都提示 E407 代理验证错误。
$ npm i typestcript
npm ERR! code E407
npm ERR! 407 Proxy Authentication Required - GET https://registry.npmjs.org/typestcript
我们的确通过配置环境变量使用了代理(内网无法直接连 npm )。这个代理工作是正常的,比如 wget https://registry.npmjs.org/typestcript 都正常下载内容。
npm config set proxy和npm config set https-proxy单独设置代理也都试过了。都不行。
NessajCN   
cat ~/.npmrc
结果 po 一下
另外也发一下你的代理设置
arfaWong   
换个国内的源吧
zhiqiang
OP
  
@NessajCN ~/.npmrc 是空的。如果设置 npm config 之后是
```
https-proxy=http://user123:[email protected]:3128/
proxy=http://user123:[email protected]:3128/
```
但无论是否设置,都是 E407 错误。环境变量设置了 https_proxy 、all_proxy 、http_proxy ,都指向上面这个代理。
zhiqiang
OP
  
@arfaWong 换国内源一样的错误。我的理解是代理那一层就出错了,还没访问最终目的地。
$ npm config set registry http://mirrors.cloud.tencent.com/npm/
$ npm install typescript
npm ERR! code E407
npm ERR! 407 Proxy Authentication Required - GET http://mirrors.cloud.tencent.com/npm/typescript
zhiqiang
OP
  
搜到一个可能有用的信息。我这个代理在其它还没升级到 24.04 的服务器上没问提。看来 24.04 的 ubuntu 或者新版本的 npm 升级了验证体系?
The dreaded NTLM
There is an HTTP status code 407 (proxy authentication required), which is the more correct way of saying it's the proxy rather than the destination server that's rejecting your request. That code plagued me for the longest time until after a lot of time on Google, I learned my proxy used NTLM authentication. HTTP basic authentication wasn't enough to satisfy whatever proxy my corporate overlords had installed. I resorted to using Cntlm on my local machine (unauthenticated), then had it handle the NTLM authentication with the upstream proxy. Then I had to tell all the programs that couldn't do NTLM to use my local machine as the proxy - which is generally as simple as setting HTTP_PROXY and HTTPS_PROXY. Otherwise, for npm use (as @Agus suggests):
npm config set proxy http://proxy.example.com:3128
npm config set https-proxy http://proxy.example.com:3128
您需要登录后才可以回帖 登录 | 立即注册

返回顶部