10

I'm having trouble installing Chocolatey packages from behind a corporate proxy. Internet Explorer is correctly configured but I'm having issues getting it to work through PowerShell.

I can use the Web-Client to download pages e.g. Microsoft.com, but ultimately Chocolatey fails to download packages with the prompt

"Please provide proxy credentials:"

which will not accept my domain login as being valid. Sometimes I just get the error

"Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (407) Proxy Authentication Required."

I have two machines - one of them can download the packages fine, and the other gives the errors above, but they both show Direct access (as below):

PS C:\Windows\system32> netsh winhttp import proxy source=ie

Current WinHTTP proxy settings:

    Direct access (no proxy server).


PS C:\Windows\system32> netsh winhttp show proxy

Current WinHTTP proxy settings:

    Direct access (no proxy server).

I'm not too sure what is happening here. Any suggestions?

StackzOfZtuff
  • 2,534
  • 1
  • 28
  • 25
clickcell
  • 439
  • 3
  • 6
  • 20
  • Check `HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable` and `HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer` on both computers, do they have the same values (should be 1 and the proxy address:port) – sodawillow Dec 14 '15 at 09:48
  • I find that they are both set to 0, even on the machine that doesn't give me any issues. If I manually set Enable to 1 and add the Server address on the other machine, it doesn't resolve the 407 errors. The only way to resolve the error is to authenticate to the proxy by navigating to any website in Internet Explorer (not Chrome), there's an automatic redirect that happens, it doesn't change the values in the registry, but it does get rid of the 407 errors. Chrome shows the same redirect taking place but does not resolve the error. – clickcell Dec 17 '15 at 11:33
  • Even once it has authenticated, I'll get issues downloading specific packages. Filezilla is an example, when it tries to fetch the installer, the proxy returns the redirect page instead, and the script will fail as the length of the file never matches the expected length. In other words, the file in %temp%\chocolatey\filezilla\3.14.1\filezillaInstall.exe is just a copy of the redirect page, if I rename that to .html and open it, it will redirect to the filezilla download as expected, but as soon as I run the choco install command the same thing happens again – clickcell Dec 17 '15 at 11:59

2 Answers2

12

Chocolatey has proxy instructions at https://github.com/chocolatey/choco/wiki/Proxy-Settings-for-Chocolatey and specifically the section on explicit proxy. Ensure you have the proper version of choco installed for that to work. If that is incorrect, we should fix the documentation/choco to make it correct.

For posterity:

Explicit Proxy Settings

Chocolatey has explicit proxy support starting with 0.9.9.9.

You can simply configure 1 or 3 settings and Chocolatey will use a proxy server. proxy is required and is the location and port of the proxy server. proxyUser and proxyPassword are optional. The values for user/password are only used for credentials when both are present.

choco config set proxy <locationandport>
choco config set proxyUser <username>
choco config set proxyPassword <passwordThatGetsEncryptedInFile>

Example

Running the following commands in 0.9.9.9:

choco config set proxy http://localhost:8888
choco config set proxyUser bob
choco config set proxyPassword 123Sup#rSecur3
ferventcoder
  • 11,952
  • 3
  • 57
  • 90
3

I had a similar issue except that Chocolately wouldn't install in the first place due to the corporate proxy.

Was able to resolve this based on this blog post...

...as follows:

  1. Open an elevated command prompt (Windows key -> Type cmd -> right-click on "Command Prompt" and select "Run as Administrator").
  2. Run the following command: @powershell -NoProfile -ExecutionPolicy Unrestricted -Command "[Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials; iex ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
  3. This should install Chocolatey without any errors. To verify it has worked, close the command prompt and open another (so the path environment variable change is picked up) and then run the choco command - if all is OK it should now output the Chocolatey version and help text.

Further note for node.js: I did the above after installing Node.js with the option ticked to install the extra tools/requirements including Chocolatey. Was then able to continue the failed installation via Apps & features -> Node.js -> Modify. I then followed the instructions here to configure npm for the corporate proxy.

StackzOfZtuff
  • 2,534
  • 1
  • 28
  • 25
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
  • Thanks, exactly what I am trying to do. I'm getting errors when I copy&paste 2 but imagine it's something on my side. – ajh158 Feb 26 '20 at 21:18
  • C:\WINDOWS\system32>@powershell -NoProfile -ExecutionPolicy Unrestricted -Command "[Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials; iex ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin Exception calling "DownloadString" with "1" argument(s): "The request was aborted: Could not create SSL/TLS secure channel." At line:1 char:92 + ... redentials; iex ((New-Object Net.WebClient).DownloadString('https://c ... + ... – ajh158 Feb 26 '20 at 21:23
  • 1
    I had to insert [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 into the command: @powershell -NoProfile -ExecutionPolicy Unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; [Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials; iex ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin – ajh158 Feb 26 '20 at 21:28