使用 Azure 逻辑应用 HTTP 操作调用 Azure 函数时出现此错误:
Http请求失败:服务器在超时限制内没有响应。请参阅逻辑应用限制:https://aka.ms/logic-apps-limits-and-config#http-limits。
我知道等待函数响应的时间有 230 秒的限制。但是,当使用 Python 触发时,该函数会在大约 150 秒内返回输出。
url = 'XXX' # Azure Function url
data = {
"Connect-Type": "application/json"
}
r = requests.post(url, data=json.dumps(data), headers={'Content-Type': 'application/json'})
有人知道可能出了什么问题吗?或者有没有办法让函数在限制内“响应”,并继续运行?
独立函数在使用最新的库时确实可以工作。
- func init LocalFunctionProj --worker-runtime dotnet-isolated --target-framework net8.0
- cd LocalFunctionProj
- func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
HttpExample.cs-
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
namespace LocalFunctionProj
{
public class HttpExample
{
private readonly ILogger _logger;
public HttpExample(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<HttpExample>();
}
[Function("HttpExample")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.WriteString("Welcome to Azure Functions!");
return response;
}
}
}
local.settings.json-
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}
程序.cs-
using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.Build();
host.Run();
host.json-
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.3-preview1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>