V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zhiqiang
V2EX  ›  Node.js

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

  •  
  •   zhiqiang · 11 天前 · 716 次点击

    不知道有人碰到没,头大。

    系统: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 proxynpm config set https-proxy单独设置代理也都试过了。都不行。

    11 条回复    2024-05-09 23:15:02 +08:00
    NessajCN
        1
    NessajCN  
       11 天前 via Android
    cat ~/.npmrc
    结果 po 一下
    另外也发一下你的代理设置
    arfaWong
        2
    arfaWong  
       11 天前
    换个国内的源吧
    zhiqiang
        3
    zhiqiang  
    OP
       11 天前
    @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
        4
    zhiqiang  
    OP
       11 天前
    @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
        5
    zhiqiang  
    OP
       11 天前
    搜到一个可能有用的信息。我这个代理在其它还没升级到 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
    zhiqiang
        6
    zhiqiang  
    OP
       11 天前
    一个更诡异的是,pnpm 没有问题。只有 npm 有问题。
    NessajCN
        7
    NessajCN  
       11 天前   ❤️ 1
    @zhiqiang 试试改成
    https-proxy=http://"user123:strategy"@10.24.10.245:3128
    proxy=http://"user123:strategy"@10.24.10.245:3128
    zhiqiang
        8
    zhiqiang  
    OP
       11 天前
    @NessajCN 还真行。。。这是为什么?之前从没看见过这种写法。
    zhiqiang
        9
    zhiqiang  
    OP
       11 天前
    不对。我搞错了。还是不行。
    NessajCN
        10
    NessajCN  
       11 天前
    @zhiqiang 那只能去翻 npm 源码看他们怎么处理 url 了...
    former
        11
    former  
       10 天前
    看错误是 npm 底层在去请求包的时候,走代理 proxy 的 user/pwd 没有设置生效
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2615 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 12:53 · PVG 20:53 · LAX 05:53 · JFK 08:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.