标签: azure-functions-core-tools

azure 函数:返回 json 对象

import logging
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = {"test":"jjj"}
    return func.HttpResponse(name)
Run Code Online (Sandbox Code Playgroud)

上面是我使用 python 预览的 azure 函数(V2)。如果我回来

func.HttpResponse(f"{name}") 
Run Code Online (Sandbox Code Playgroud)

它有效,但如果我返回 dict 对象,则无效。显示的错误是

Exception: TypeError: reponse is expected to be either of str, bytes, or bytearray, got dict
Run Code Online (Sandbox Code Playgroud)

请帮忙。

azure-functions azure-functions-core-tools

9
推荐指数
3
解决办法
1万
查看次数

在本地运行Azure功能(V2)时抛出Newtonsoft.Json.JsonReaderException

我在VS2017中创建了Azure功能v2的队列触发器模板.当我在本地运行项目时,函数运行时已成功启动.但是当我在队列中创建一条消息时,VS下载了一个JsonSerialization.cs文件并指出了错误. 在此输入图像描述

默认异常设置的详细信息: 在此输入图像描述

它是由VS生成的模板,因此似乎没有像我在其他帖子中找到的代码问题.

我尝试过的:

  • 将项目发布到Azure,有效.
  • 使用npm安装的功能核心工具(Cli)运行项目,也可以.

我猜这个问题与VS使用的函数Cli有关.但它的运行时版本2.0.11651.0与npm安装的版本相同.

有没有人见过这个或有任何想法?提前致谢.

azure azure-functions azure-functions-core-tools

8
推荐指数
1
解决办法
441
查看次数

如何在本地运行 Azure 函数时获取日志?

我正在通过 azure-functions-core-tools v2.2.70 在 mac High Sierra 上本地开发/调试我的 Function App。我的应用程序基于 Node.js 8.11.1。

当我的应用程序在 Azure 上发布时,我可以获得由 记录的日志context.log("sample message"),但是,在由 本地运行应用程序时func host start,我看不到任何海关日志。也就是说,如果我通过 context.log 或 console.log 记录某些内容,我将看不到它。

我什至尝试过NODE_OPTIONS=--inspect func host start,但即便如此也无济于事。

你能告诉我如何获得我的自定义日志吗?因为没有日志记录,调试变得困难。

仅供参考,在我的 host.json 中,我有以下内容:

{
  "version": "2.0",
  "tracing": {
    "consoleLevel": "verbose"
  },
  "logging": {
    "fileLoggingMode": "always"
  }
}
Run Code Online (Sandbox Code Playgroud)

azure-functions azure-functions-core-tools

8
推荐指数
1
解决办法
4048
查看次数

Azure functions deploying fail from VS Code

I am trying to deploy my azure function (python) from VS code and it's giving the below error.

I was able to debug my code in my local machine without any error, and I am not understanding why deployment is failing.

11:55:51 PM nhtsacleanse:正在检测平台... 11:55:51 PM nhtsacleanse:错误:哎呀...发生了意外错误。 11:55:53 PM nhtsacleanse:/opt/Kudu/Scripts/starter.sh oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform python --platform-version 3.7 -p packagedir=.python_packages /lib/site-packages 11:55:57 PM nhtsacleanse:部署失败。

在此输入图像描述

Created azure function app in azure portal

在此输入图像描述

在此输入图像描述

在此输入图像描述

azure-functions azure-functions-core-tools

8
推荐指数
3
解决办法
2万
查看次数

无法加载类型 Microsoft.Azure.WebJobs.ParameterBindingData

我目前正在 VS Code 中开发 Azure 函数。我遇到了一个错误,该错误已在此 GitHub问题中报告。错误全文如下:Microsoft.Azure.WebJobs.Extensions.ServiceBus: Could not load type 'Microsoft.Azure.WebJobs.ParameterBindingData' from assembly 'Microsoft.Azure.WebJobs, Version=3.0.34.0, Culture=neutral, PublicKeyToken=****'. Value cannot be null. (Parameter 'provider')

建议的解决方案之一是降级Microsoft.Azure.WebJobs.Extensions.Storage. 但是,我不知道如何从扩展包降级包。在我的本地开发环境中,我使用以下默认host.json配置:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.15.0, 4.0.0)"
  }
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了多个版本范围,每个版本范围都会导致相同的错误。由于我不熟悉.NET,因此我希望获得有关如何降级软件包以解决此问题的任何帮助或建议。谢谢。

附加信息: 我正在使用测试触发器在本地开发 EventHub 触发函数:

@app.function_name(name="EventHubTrigger1")
@app.event_hub_message_trigger(arg_name="myhub", event_hub_name="samples-workitems",
                               connection="") 

def test_function(myhub: func.EventHubEvent):
    logging.info('Python EventHub trigger processed an event: %s',
                myhub.get_body().decode('utf-8')) …
Run Code Online (Sandbox Code Playgroud)

azure azure-functions azure-functions-core-tools

8
推荐指数
2
解决办法
1万
查看次数

Azure 函数 Cosmos DB 输出绑定 - 自定义 JsonSerializerSettings

我有一个带有 CosmosDB 输出绑定的 Azure 函数,如下所示:

public static class ComponentDesignHttpTrigger
{
    [FunctionName("ComponentDesignInserter-Http-From-ComponentDesign")]
    public static IActionResult Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "fromComponentDesign")] HttpRequest request,
        [CosmosDB(
            databaseName: StorageFramework.CosmosDb.DatabaseId,
            collectionName: Storage.ComponentDesignCollectionId,
            ConnectionStringSetting = "CosmosDBConnection")] out ComponentDesign componentDesignToInsert,
        ILogger log)
    {
        var requestBody = new StreamReader(request.Body).ReadToEnd();
        componentDesignToInsert = JsonConvert.DeserializeObject<ComponentDesign>(requestBody);

        return new OkObjectResult(componentDesignToInsert);
    }
}
Run Code Online (Sandbox Code Playgroud)

在这个函数componentDesignToInsert中,函数执行完成后会自动序列化并放入 CosmosDB。但是默认的序列化不会把东西放在camelCase中。为此,Json.NET 允许您提供自定义序列化程序设置,如下所示:

var settings = new JsonSerializerSettings
{
    ContractResolver = new CamelCasePropertyNamesContractResolver()
};

var json = JsonConvert.SerializeObject(yourObject, settings);
Run Code Online (Sandbox Code Playgroud)

但我不确定如何将它与我的输出绑定集成。我怎样才能做到这一点?

azure json.net azure-functions azure-cosmosdb azure-functions-core-tools

7
推荐指数
1
解决办法
493
查看次数

Azure函数IWebJobsStartup实现中的ExecutionContext

如何获取对函数启动类中的ExecutionContext.FunctionAppDirectory的访问权限,以便我可以正确设置我的Configuration。请查看以下启动代码:

[assembly: WebJobsStartup(typeof(FuncStartup))]
namespace Function.Test
{
    public class FuncStartup : IWebJobsStartup
    {
        public void Configure(IWebJobsBuilder builder)
        {
            var config = new ConfigurationBuilder()
               .SetBasePath(“”/* How to get the Context here. I cann’t DI it 
                           as it requires default constructor*/)
               .AddJsonFile(“local.settings.json”, true, reloadOnChange: true)
               .AddEnvironmentVariables()
               .Build();

        }
    }
 }
Run Code Online (Sandbox Code Playgroud)

azure azure-functions azure-functions-runtime azure-functions-core-tools

7
推荐指数
2
解决办法
1060
查看次数

带有点网隔离 Az 函数的 Fiddler - 启动 gRPC 调用时出错

我在 VS2019 中有一个 C# dotnet 5 Azure Function,配置为“FUNCTIONS_WORKER_RUNTIME”:“dotnet-isolated”。

如果我在 Fiddler 运行时在开发环境 (ctrl + F5) 中运行该函数,则会收到以下错误:

Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="启动 gRPC 调用时出错。HttpRequestException: 在未启用 HTTP/2 时使用版本策略 RequestVersionOrHigher 请求 HTTP 版本 2.0。

如果 Fiddler 未运行,该函数将正常运行。

有人知道如何解决这个问题吗?

fiddler .net-core azure-functions azure-functions-core-tools

7
推荐指数
1
解决办法
1690
查看次数

无法在 VS Code IDE 中调试 Python Azure 函数。获取连接 ECONNREFUSED 127.0.0.1:9091 错误

我正在尝试使用 VS code IDE 调试 Azure 函数 python 代码。
Local.settings.json 使用以下配置更新

"AzureWebJobsStorage": "UseDevelopmentStorage=true"
Run Code Online (Sandbox Code Playgroud)

到目前为止我尝试过的事情:-

  • 我重新安装了VS代码,
  • 将 Azure Function Core 工具从 4.0 降级到 3.0
  • 任何解决这个问题的指示都会非常有帮助。

以下是尝试调试用 Python 编写的 Azure 函数时 VS Code IDE 上的错误:

在此输入图像描述

下面的Host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "functionTimeout": "20:00:00",
  "extensions": {
    "durableTask": {
      "maxConcurrentActivityFunctions": 1
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

下面是launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Python …
Run Code Online (Sandbox Code Playgroud)

visual-studio-code azure-functions azure-functions-runtime azure-functions-core-tools azurite

7
推荐指数
1
解决办法
9706
查看次数

本地 Azure 功能:客户包不在系统路径中。这绝对不应该发生

我在本地遇到 azure 函数的奇怪警告。每当我func start执行函数时,我都会收到以下错误消息:

Found Python version 3.10.12 (python3).

Azure Functions Core Tools
Core Tools Version:       4.0.5455 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.27.5.21554

[2023-11-14T10:02:39.795Z] Customer packages not in sys path. This should never happen!
[2023-11-14T10:02:42.194Z] Worker process started and initialized.
Run Code Online (Sandbox Code Playgroud)

在host.json中,extensionBundle版本是[3.*, 4.0.0) 在local.settings.json中,"FUNCTIONS_WORKER_RUNTIME": "python" 函数app基于python azure函数的新模型(func init MyProjFolder --worker-runtime python --model V2 https://learn. microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=linux%2Cisolated-process%2Cnode-v4%2Cpython-v2%2Chttp-trigger%2Ccontainer-apps&pivots=programming-language-python )

我的第一次审讯是第一次警告:

Customer packages not in sys path. This should never happen!。我正在使用虚拟环境。

功能正常启动,但是这个警告是什么?

本地.settings.json:

Found Python version 3.10.12 (python3). …
Run Code Online (Sandbox Code Playgroud)

python azure-functions azure-functions-core-tools

7
推荐指数
2
解决办法
5305
查看次数