[英]Getting Azure Python function exception body with Powershell
我有一个 Azure Python function:
def main(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse('TEST ERROR MESSAGE', status_code=403)
当我通过 Powershell 调用 function 时,我只收到一般的 403 错误消息:“远程服务器返回错误:(403)禁止。我无法提取消息“测试错误消息”,我不确定为什么。任何帮助将不胜感激,我在网上找不到任何东西。我的 PowerShell 或 Python 中的错误是什么?我正在提出请求并捕获以下异常:
try
{$response = Invoke-WebRequest -URI "https/path/to/func" -Method Get -CertificateThumbprint $Thumb -ErrorAction stop}
catch
{$response = $_.Exception}
但是,如果我将 status_code 设置为 200,我可以很好地看到消息“TEST ERROR MESSAGE”
我会尝试使用Invoke-RestMethod
而不是Invoke-WebRequest
来复制问题
PowerShell v6+ 中的Invoke-WebRequest
和Invoke-RestMethod
也有了显着改进,因此如果您仍在使用 v5.1,那么您将需要做更多的工作才能获得错误响应代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.