Skip to content

Proxy Error 407 System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required. #26402

Open

Description

Description

Hi,

the Powershell Az module does not support proxy authentication. $env:HTTP_PROXY and $env:HTTPS_PROXY are set (otherwise i would not get the 407 response) to our corporate proxy.
I tried also some authentication commands like (New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
upfront but still i get a 407.

Issue script & Debug output

PS> $env:HTTP_PROXY="http..."
PS> $env:HTTPS_PROXY="http..."
PS> (New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
PS> Connect-AzAccount -Debug

DEBUG: 07:57:45 - [InteractiveUserAuthenticator] Calling InteractiveBrowserCredential.AuthenticateAsync with
TenantId:'', Scopes:'https://management.core.windows.net//.default',
AuthorityHost:'https://login.microsoftonline.com/', RedirectUri:'http://localhost:8400/'
DEBUG: InteractiveBrowserCredential.Authenticate invoked. Scopes: [ https://management.core.windows.net//.default ]
ParentRequestId:
DEBUG: Executing interactive authentication workflow inline.
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET Framework 4.8.9277.0 Microsoft Windows 10.0.22631 [2024-10-21 05:57:45Z -
a77cefbe-2094-4d48-9920-4b3bf139d081] MSAL MSAL.CoreCLR with assembly version '4.61.3.0'.
CorrelationId(a77cefbe-2094-4d48-9920-4b3bf139d081)
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET Framework 4.8.9277.0 Microsoft Windows 10.0.22631 [2024-10-21 05:57:45Z -
a77cefbe-2094-4d48-9920-4b3bf139d081] === InteractiveParameters Data ===
LoginHint provided: False
User provided: False
UseEmbeddedWebView: NotSpecified
ExtraScopesToConsent:
Prompt: select_account
HasCustomWebUi: False
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET Framework 4.8.9277.0 Microsoft Windows 10.0.22631 [2024-10-21 05:57:45Z -
a77cefbe-2094-4d48-9920-4b3bf139d081]
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenInteractive
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - xxxxxxxxx
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured:
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET Framework 4.8.9277.0 Microsoft Windows 10.0.22631 [2024-10-21 05:57:45Z -
xxxxxxxxx] === Token Acquisition (InteractiveRequest) started:
Scopes: https://management.core.windows.net//.default
Authority Host: login.microsoftonline.com
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET Framework 4.8.9277.0 Microsoft Windows 10.0.22631 [2024-10-21 05:57:45Z -
xxxxxxxxx] [Instance Discovery] Instance discovery is enabled and will be performed
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET Framework 4.8.9277.0 Microsoft Windows 10.0.22631 [2024-10-21 05:57:45Z -
xxxxxxxxx] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET Framework 4.8.9277.0 Microsoft Windows 10.0.22631 [2024-10-21 05:57:45Z -
xxxxxxxxx] Fetching instance discovery from the network from host
login.microsoftonline.com.
DEBUG: Request [xxxxxxxxx] GET
https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=REDACTED
x-client-SKU:REDACTED
x-client-Ver:REDACTED
x-client-OS:REDACTED
client-request-id:REDACTED
return-client-request-id:REDACTED
x-app-name:REDACTED
x-app-ver:REDACTED
x-ms-client-request-id:xxxxxxxxx
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Identity/1.12.0 (.NET Framework 4.8.9277.0; Microsoft Windows 10.0.22631 )
client assembly: Azure.Identity
DEBUG: Request [c7b1ef34-1cdc-4d2a-a976-36c9f2b444b2] exception Azure.RequestFailedException: An error occurred while
sending the request. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. --->
System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpClientTransport.d__12.MoveNext()
--- End of inner exception stack trace ---
at Azure.Core.Pipeline.HttpClientTransport.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpPipelineTransportPolicy.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.ResponseBodyPolicy.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.LoggingPolicy.d__9.MoveNext()

Environment data

PS> $PSVersionTable

Name Value


PSVersion 5.1.22621.4111
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.4111
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Module versions

PS> Get-Module Az*

ModuleType Version Name ExportedCommands


Script 3.0.4 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}

Error output

PS> Resolve-AzError

HistoryId: 2

Message : DeviceCodeCredential authentication failed: Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by
configuring a custom retry policy in ClientOptions.RetryPolicy.
StackTrace : at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, String additionalMessage, Boolean isCredentialUnavailable)
at Azure.Identity.DeviceCodeCredential.d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Identity.DeviceCodeCredential.d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.PowerShell.Authenticators.MsalAccessToken.d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzureAccount account,
IAzureEnvironment environment, String tenant, SecureString password, String promptBehavior, Action1 promptAction, IAzureTokenCache tokenCache, String resourceId) at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.AcquireAccessToken(IAzureAccount account, IAzureEnvironment environment, String tenantId, SecureString password, String promptBehavior, Action1 promptAction, String resourceId)
at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.ListAccountTenants(IAzureAccount account, IAzureEnvironment
environment, SecureString password, String promptBehavior, Action1 promptAction) at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account, IAzureEnvironment environment, String tenantIdOrName, String subscriptionId, String subscriptionName, SecureString password, Boolean skipValidation, IOpenIDConfiguration openIDConfigDoc, Action1 promptAction, String name, Boolean shouldPopulateContextList, Int32 maxContextPopulation, String authScope,
Boolean IsInteractiveContextSelectionEnabled)
at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass134_2.b__7()
at System.Threading.Tasks.Task1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass134_1.<ExecuteCmdlet>b__1(AzureRmProfile localProfile, RMProfileClient profileClient, String name) at Microsoft.Azure.Commands.Profile.Common.AzureContextModificationCmdlet.ModifyContext(Action2 contextAction)
at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.SetContextWithOverwritePrompt(Action`3 setContextAction)
at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : Azure.Identity.AuthenticationFailedException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : An error occurred while sending the request.
StackTrace : at Azure.Core.Pipeline.HttpClientTransport.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpPipelineTransportPolicy.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.ResponseBodyPolicy.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.LoggingPolicy.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.RedirectPolicy.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Azure.Core.Pipeline.RetryPolicy.d__5.MoveNext()
Exception : Azure.RequestFailedException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : An error occurred while sending the request.
StackTrace : at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpClientTransport.d__12.MoveNext()
Exception : System.Net.Http.HttpRequestException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : The remote server returned an error: (407) Proxy Authentication Required.
StackTrace : at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
Exception : System.Net.WebException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : An error occurred while sending the request.
StackTrace : at Azure.Core.Pipeline.HttpClientTransport.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpPipelineTransportPolicy.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.ResponseBodyPolicy.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.LoggingPolicy.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.RedirectPolicy.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Azure.Core.Pipeline.RetryPolicy.d__5.MoveNext()
Exception : Azure.RequestFailedException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : An error occurred while sending the request.
StackTrace : at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpClientTransport.d__12.MoveNext()
Exception : System.Net.Http.HttpRequestException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : The remote server returned an error: (407) Proxy Authentication Required.
StackTrace : at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
Exception : System.Net.WebException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : An error occurred while sending the request.
StackTrace : at Azure.Core.Pipeline.HttpClientTransport.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpPipelineTransportPolicy.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.ResponseBodyPolicy.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.LoggingPolicy.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.RedirectPolicy.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Azure.Core.Pipeline.RetryPolicy.d__5.MoveNext()
Exception : Azure.RequestFailedException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : An error occurred while sending the request.
StackTrace : at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpClientTransport.d__12.MoveNext()
Exception : System.Net.Http.HttpRequestException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : The remote server returned an error: (407) Proxy Authentication Required.
StackTrace : at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
Exception : System.Net.WebException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : An error occurred while sending the request.
StackTrace : at Azure.Core.Pipeline.HttpClientTransport.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpPipelineTransportPolicy.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.ResponseBodyPolicy.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.LoggingPolicy.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.RedirectPolicy.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Azure.Core.Pipeline.RetryPolicy.d__5.MoveNext()
Exception : Azure.RequestFailedException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : An error occurred while sending the request.
StackTrace : at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Azure.Core.Pipeline.HttpClientTransport.d__12.MoveNext()
Exception : System.Net.Http.HttpRequestException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Message : The remote server returned an error: (407) Proxy Authentication Required.
StackTrace : at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
Exception : System.Net.WebException
InvocationInfo : {Connect-AzAccount}
Line : connect-azaccount -DeviceCode
Position : At line:1 char:1
+ connect-azaccount -DeviceCode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedneeds-triageThis is a new issue that needs to be triaged to the appropriate team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions