Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands run once only, then throw error sending the request #17103

Closed
Aurilium opened this issue Feb 14, 2022 · 4 comments · Fixed by #17129
Closed

Commands run once only, then throw error sending the request #17103

Aurilium opened this issue Feb 14, 2022 · 4 comments · Fixed by #17129
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported needs-author-feedback More information is needed from author to address the issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@Aurilium
Copy link

Description

Hi, I'm not sure if this fits better into bug reports or questions to Az but I'm facing severe problems with the Az module preventing me to use Azure with PowerShell.
My problem:
I installed the Az module (details below at "What I did") and started testing the connection testing some basic cmdlets for querying resources lists and similar. Everything was fine until I executed one cmdlet a second time. Then I received the error "An error occurred while sending the request" I tried different cmdlets and they worked - but also only the first time. When I execute any command a second time it will fail with this error message. I can disconnect but then I can't reconnect since I'd need to execute the connect command a second time and it fails with "Connect-AzAccount : An error occurred while sending the request"

What I did:

  • Installed Az by "Install-Module -Name Az -Scope CurrentUser -Repository PSGallery"
  • faced the error as described
  • uninstalled Az package according to the docs here [Uninstall Azure PowerShell | Microsoft Docs](https://docs.microsoft.com/en-us/powershell/azure/uninstall-az-ps?view=azps-7.2.0
  • reinstalled it as above
  • still facing the same error
  • I opened a MS premier support ticket but they sent me here
    (note: maybe the first installation was interrupted by some company update procedure killing my PS session. Maybe, I'm not sure, since it took more than 10 minutes to install without any output. That's why I uninstalled and reinstalled)

There are quite restrictive policies in place on my company's client PC as well as the network. That might be the cause but I don't know how to tackle this problem or analyze its root further. Maybe the cause is the (maybe) failed first installation of the Az package. Perhaps the uninstall guide in the docs linked above is not clean enough? I don't know what else might be the root cause since the cmdlets I tried do work for the first time in a session but afterwards they fail.
I tried using Az from MS Code until it fails. If I try to connect to Azure using a plain PS window 10 minutes later it still fails. It only recovers after some more time. Then I can run commands again, once.
I'd be very glad if you can help here.

Issue script & Debug output

> Get-AzStorageAccount
DEBUG: 12:21:57 - GetAzureStorageAccountCommand begin processing with ParameterSet 'ResourceGroupParameterSet'.
DEBUG: 12:21:57 - using account id '<REDACTED>'...
DEBUG: [Common.Authentication]: Authenticating using Account: '<REDACTED>', environment: 'AzureCloud', tenant: '<REDACTED>'
DEBUG: 12:21:57 - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'<REDACTED>', Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:'<REDACTED>'
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Azure region was not configured or could not be discovered. Not using a regional authority.
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57] Found 1 cache accounts and 0 broker accounts
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57] Returning 1 accounts
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] MSAL MSAL.Desktop with assembly version '4.30.1.0'. CorrelationId(<REDACTED>)
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] === AcquireTokenSilent Parameters ===
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] LoginHint provided: False
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Account provided: True
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] ForceRefresh: False
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] 
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - <REDACTED>

DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] === Token Acquisition (SilentRequest) started:

        Authority Host: login.microsoftonline.com
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Azure region was not configured or could not be discovered. Not using a regional authority.
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Access token is not expired. Returning the found cache entry. [Current time (01/19/2022 11:21:57) - Expiration Time (01/19/2022 12:22:41 +00:00) - Extended Expiration Time (01/19/2022 12:22:41 +00:00)]
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Returning access token found in cache. RefreshOn exists ? False
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] Fetched access token from host login.microsoftonline.com.
DEBUG: (False) MSAL 4.30.1.0 MSAL.Desktop Windows 10 Enterprise [01/19/2022 11:21:57 - ] === Token Acquisition finished successfully. An access token was returned with Expiration Time: 01/19/2022 12:22:41 +00:00 and Scopes https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:  ExpiresOn: 2022-01-19T12:22:41.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '<REDACTED>', UserId: '<REDACTED>'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/<REDACTED>/providers/Microsoft.Storage/storageAccounts?api-version=2021-06-01

Headers:
x-ms-client-request-id        : <REDACTED>
accept-language               : en-US

Body:



Get-AzStorageAccount : Fehler beim Senden der Anforderung.
In Zeile:1 Zeichen:1
+ Get-AzStorageAccount 
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzStorageAccount], HttpRequestException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Management.Storage.GetAzureStorageAccountCommand

DEBUG: AzureQoSEvent: Module: Az.Storage:4.1.1; CommandName: Get-AzStorageAccount; PSVersion: 5.1.18362.1801; IsSuccess: False; Duration: 00:00:00.2978734; Exception: Fehler beim Senden der Anforderung.;
DEBUG: Finish sending metric.
DEBUG: 12:21:59 - GetAzureStorageAccountCommand end processing.

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.18362.1801
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.1801
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module versions

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.7.2      Az.Accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount...}
Script     5.3.0      Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment...}
Script     4.2.0      Az.Storage                          {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountManagementPolicyAction, Add-AzStorageAccountNetworkRule, Close-AzStorageFileHandle...}

Error output

Connect-AzAccount : Fehler beim Senden der Anforderung. (EN: An error occurred while sending the request)
In Zeile:1 Zeichen:1
+ Connect-AzAccount -Tenant $tenantID
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Connect-AzAccount], HttpRequestException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
@Aurilium Aurilium added bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Feb 14, 2022
@ghost ghost added question The issue doesn't require a change to the product in order to be resolved. Most issues start as that customer-reported and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Feb 14, 2022
@dingmeng-xue
Copy link
Member

dingmeng-xue commented Feb 16, 2022

Hi @Aurilium , thanks for contacting us.

According to the debug message, module is installed successfully and HTTP request is created. But request cannot be sent out due to unknown reason. Could you check things below?

  1. Is there proxy setting?
  2. Could you leverage HTTP traffic monitor tool at client such as Fiddler? Fiddler might show more information about HTTP communication.
  3. Try this code repeatedly Invoke-AzRestMethod -Path \subscriptions?api-version=2020-01-01. I believe you will fail again second time.
  4. try below code in PowerShell 7.x repetedly. Its HTTP call is not sent by Azure PowerShell but just PowerShell.
$token = ConvertTo-SecureString (Get-AzAccessToken).Token -AsPlainText
Invoke-RestMethod https://management.azure.com//subscriptions?api-version=2020-01-01 -Token $token -Authentication Bearer

@dingmeng-xue dingmeng-xue added the needs-author-feedback More information is needed from author to address the issue. label Feb 16, 2022
@Aurilium
Copy link
Author

Hi @dingmeng-xue thank you for your response!
There are proxy settings but they work for the other scripts I developed or used currently, e.g. for SPO using the PnP module and even with the problematic Az it does work the first time I execute any command. Could it be a proxy problem anyway? (Odds are not too bad for that, because I work in a quite restricted network environment but the behaviour does indicate otherwise I'd guess.)
Problem with fiddler is, I'm not allowed to use it. A colleague told me the information output is quite limited due to our network restrictions. If it turns out there's no other way to solve this problem, I might need to ignore if I'm allowed to or not ;).
For 3&4 I'll try that tomorrow as soon as I find time and report back. Thanks for you help so far!

@ghost ghost added needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-author-feedback More information is needed from author to address the issue. labels Feb 16, 2022
@Aurilium
Copy link
Author

Aurilium commented Feb 21, 2022

Hi, sorry it took so long, it's quite busy here at the moment. So I tried to do steps 3 and 4 but found that I can't send any cmdlet/request anymore and get the same error message immediately.
#4 threw some other errors. I think your assumption for the cause to be in the network was right and will try to figure something out with the networks department. Thank you. I'll report back if I succeeded.

@dingmeng-xue
Copy link
Member

@Aurilium , thanks for the information. Please contact us if you have further update. I will keep this issue open for a while.

@dingmeng-xue dingmeng-xue added needs-author-feedback More information is needed from author to address the issue. and removed needs-team-attention This issue needs attention from Azure service team or SDK team labels Feb 21, 2022
@dingmeng-xue dingmeng-xue linked a pull request Feb 21, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported needs-author-feedback More information is needed from author to address the issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants