从PowerShell连接到Azure时出错

时间:2019-07-15 14:19:07

标签: azure powershell

我使用Powershell连接到Azure。

我可以使用以下命令连接一次或两次,但是在第三次尝试中我给了我错误。

我尝试过clear-azcontext,disconnect-azaccount。但是错误仍然出现在以下命令的第三或第四次尝试中。

命令

Connect-AzAccount -Subscription ***-***-Tenant ***-*** -Environment ***-Credential $Credential

错误:

Connect-AzAccount : An error occurred while sending the request

At line:1 char:1
+ Connect-AzAccount -Subscription ***-*** -Tenant ***-***...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Connect-AzAccount], HttpRequestException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand

3 个答案:

答案 0 :(得分:0)

powershell cmdlet,有时无法给出正确的错误消息。因此,要解决此问题,您可以尝试重新安装或更新相关模块。

或者,您可以在执行 $DebugPreference= "Continue"

之前尝试使用 Connect-AzAccount

它确定PowerShell如何响应由脚本,cmdlet或提供程序或命令行中的Write-Debug命令生成的调试消息。

某些cmdlet显示调试消息,这些消息通常是为程序员和技术支持专业人员设计的非常技术性的消息。默认情况下,不显示调试消息,但是您可以通过更改$ DebugPreference的值来显示调试消息。

您可以阅读有关 $DebugPreference here的更多信息。 相同的示例输出:

PS> $ErrorView                         # Verify the value.
NormalView

PS> Get-ChildItem nofile.txt           # Find a non-existent file.
Get-ChildItem : Cannot find path 'C:\nofile.txt' because it does not exist.
At line:1 char:14
+ Get-ChildItem  <<<< nofile.txt



Status Code:
NotFound

Headers:
Pragma                        : no-cache
x-ms-failure-cause            : gateway
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-request-id               : 65972d3e-495e-41fd-84fd-9b068c62df22
x-ms-correlation-request-id   : 65972d3e-xx-41fd-84fd-xx
x-ms-routing-request-id       : xxx:xxx:65972d3e-xx-41fd-84fd-xx
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Tue, 04 Sep 2018 02:45:49 GMT

Body:
{
  "error": {
    "code": "ResourceGroupNotFound",
    "message": "Resource group 'test' could not be found."
  }
}

希望有帮助。

答案 1 :(得分:0)

尝试以管理员身份运行Powershell,用categories = ['category1', 'category2'] topics = ['topic1', 'topic2'] l1 = [] l2 = [] l3 = [] l4 = [] for c in categories: for t in topics: l1.append(c) l2.append(test[c].sum()) l3.append(t) l4.append(test[test[c] > 0][t].sum()) d = {'category':l1, 'category_count':l2, 'topic':l3, 'topic_count':l4} test_new = pd.DataFrame(d) test_new 更新模块,然后再次登录。这样就可以了。

答案 2 :(得分:0)

首先尝试从Powershell运行以下内容

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

然后再次运行connect-az命令以查看其是否有效。