我正在嘗試按照 Microsoft 指南在本地運行 Azure 函式: https ://docs.microsoft.com/nl-nl/azure/azure-functions/create-first-function-cli-python?tabs=azure-cli ,bash,browser#create-venv
無論我嘗試什么,當我嘗試使用“func start”啟動函式時,我都會一遍又一遍地得到同樣的錯誤:
Found Python version 3.8.0 (py).
Azure Functions Core Tools
Core Tools Version: 4.0.4544 Commit hash: N/A (64-bit)
Function Runtime Version: 4.3.2.18186
Could not load file or assembly 'Microsoft.Azure.WebJobs.Script.Abstractions,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=3c5b9424214e8f8c'. The system cannot find
the file specified.
我的檔案設定如下
主機.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
local.setting.json
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
}
}
要求.txt
azure-functions
函式.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "Anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
初始化檔案
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
任何幫助,將不勝感激!
uj5u.com熱心網友回復:
我也遇到過這個。不知道是什么原因造成的。
但是為我解決的問題是下載、卸載和重新安裝Azure Functions Core Tools (使用“修復”只是回傳了一個通用的“由于錯誤而失敗”,我不得不殺死 PowerToys)
不確定是否有必要,但我也清除了我的 nuget 快取
dotnet nuget locals all -c
dotnet restore # in your sln folder
并重新安裝了我的 vscode Azure 插件
uj5u.com熱心網友回復:
我在使用 Azure CLI 運行 Azure Function v4 時遇到了完全相同的問題:
"azure-cli": "2.37.0",
"azure-cli-core": "2.37.0",
"azure-cli-telemetry": "1.0.6",
"extensions": {}
我通過重新安裝 Azure Functions Core Tools 來修復它(Lightfire 的部分答案)所有其他操作對我都沒有影響。
安裝 Azure Functions 核心工具的鏈接
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/484899.html
上一篇:Python:無法在單獨的函式中呼叫函式?(未定義名稱“getItemClassiness”)
下一篇:位停留在找到限制下的最大可能值
