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-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) 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.
Created azure function app in azure portal
我目前正在 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) 我有一个带有 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
如何获取对函数启动类中的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
我在 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
我正在尝试使用 VS code IDE 调试 Azure 函数 python 代码。
Local.settings.json 使用以下配置更新
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的事情:-
以下是尝试调试用 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
我在本地遇到 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) azure-functions ×10
azure-functions-core-tools ×10
azure ×4
.net-core ×1
azurite ×1
fiddler ×1
json.net ×1
python ×1