wget不采用variableshttp_proxy

如果我运行:

echo $http_proxy 

它输出:

 http://user:pass@host:port 

但是当我运行:

 wget www.google.com 

它输出:

 Resolviendo www.google.com... 209.85.195.104 Caching www.google.com => 209.85.195.104 Conectando a www.google.com|209.85.195.104|:80... Closed fd 3 falló: Expiró el tiempo de conexión. Releasing 0x088293a8 (new refcount 1). Reintentando. --2010-07-07 19:40:00-- (intento: 2) http://www.google.com/ Found www.google.com in host_name_addresses_map (0x88293a8) Conectando a www.google.com|209.85.195.104|:80... 

用英语:

 Resolving www.google.com... 209.85.195.104 Caching www.google.com => 209.85.195.104 conecting to www.google.com|209.85.195.104|:80... Closed fd 3 fail: conection time has expired. Releasing 0x088293a8 (new refcount 1). retrying. ... 

我做错了什么?

注意: https_proxy和ftp_proxy具有相同的值。 而且我已经尝试修改/ etc / wgetrc并重新启动而没有成功。

感谢您的debugging日志。

所以你显然没有使用基于该输出的预期的env代理设置。

有关configuration代理设置的其他方法,请参阅http://www.gnu.org/software/wget/manual/wget.html#Proxies 。

目前还不清楚你是否处在某种受控的环境中,但也可能是你所调用的wget已经被修改过了 – 也许有一个包装脚本会剥离掉环境或者禁用代理设置使用( --no-proxy )。 file $(which wget)显示它是一个可执行文件?

为了将shell中定义的variables传递给subprocess,必须将其导出。 未能导出它们可能会导致您描述的问题。 以下是我自己的terminal的一个例子:

首先,我尝试下载页面,发现它没有使用我的代理。

  sh-3.2 $ wget serverfault.com
 -  2016-11-03 18:46:15  -  http://serverfault.com/
解决serverfault.com ... 151.101.65.69,151.101.129.69,151.101.193.69,...
连接到serverfault.com | 151.101.65.69 |:80 ... ^ C 

我发现我的方式的错误,并定义环境variables。

  sh-3.2 $ http_proxy =“http://proxy.example.com:80/”
 sh-3.2 $ echo $ http_proxy
 http://proxy.example.com:80/
 sh-3.2 $ wget serverfault.com
 -  2016-11-03 18:46:53  -  http://serverfault.com/
解决serverfault.com ... 151.101.65.69,151.101.129.69,151.101.193.69,...
连接到serverfault.com | 151.101.65.69 |:80 ... ^ C 

不幸的是,它仍然不起作用。 问题是,我没有导出variables后,我定义,所以subprocess无法看到它。

  sh-3.2 $ env |  grep http_proxy
 sh-3.2 $ export http_proxy
 sh-3.2 $ env |  grep http_proxy
 HTTP_PROXY = HTTP://proxy.example.com:80 / 

wget现在应该尝试使用我的代理。

  sh-3.2 $ wget serverfault.com
 --2016-11-03 18:48:30-- http://serverfault.com/
正在parsingproxy.example.com ...失败:节点名或服务器名已提供或未知。
 wget:无法parsing主机地址“proxy.example.com” 

这是Ubuntu吗? 请参阅https://bugs.launchpad.net/ubuntu/+source/wget/+bug/585766上的解决方法。

此外,除了设置http_proxy环境variables外,您可能还需要在.wgetrc中设置“proxy = on”。 我认为这在http://www.gnu.org/software/wget/manual/wget.html#Proxies中隐约提出。

另外,尝试设置$ HTTP_PROXY。

你在/ etc / wgetrc或〜/ .wgetrc中定义了http_proxy吗? Wget似乎没有读取环境variables,但当我在其中的一个文件中定义它时,它对我很有用。

编辑:我不需要修改wgetrc如果我在〜/ .bashrc中设置http_proxy并从/ etc /环境中删除no_proxy。