我在Python中有一个带有定时器触发器的Azure函数。要按需进行本地测试,我将runnstartup选项设置为True(此处是Microsoft文档)。
我的简化Python代码看起来像这样:
import logging
import azure.functions as func
import sendgrid
from sendgrid import SendGridAPIClient
import azure.storage.blob
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
import wikipedia
import json, os
from datetime import datetime
//Initializations
def main(mytimer: func.TimerRequest, inputblob: func.InputStream) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
if mytimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function ran at %s', utc_timestamp)
// Do stuff
我的 function.json(带有计时器触发器和 blob 输入绑定):
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 30 9 * * *",
"runOnStartup": true
},
{
"name": "inputblob",
"type": "blob",
"path": "sharefiles/versionIds.json",
"connection": "shareFilesConnString",
"direction": "in"
}
]
}
和我的hosts.json:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}
然而,当我在本地计算机上运行该函数进行测试时,我得到了以下输出。最明显的错误是:
系统。Private.CoreLib:执行函数时出现异常:函数..微软。Azure.WebJobs.Script:未找到任何已初始化的语言工作器。
Executing task: .venv\Scripts\activate ; func host start <
Found Python version 3.7.5 (python).
%%%%%%
%%%%%%
@ %%%%%% @
@@ %%%%%% @@
@@@ %%%%%%%%%%% @@@
@@ %%%%%%%%%% @@
@@ %%%% @@
@@ %%% @@
@@ %% @@
%%
%
Azure Functions Core Tools (2.7.1948 Commit hash: 29a0626ded3ae99c4111f66763f27bb9fb564103)
Function Runtime Version: 2.0.12888.0
[12/10/2019 8:11:29 PM] File 'C:\Program Files\dotnet\dotnet.exe' is not found, 'dotnet' invocation will rely on the PATH environment variable.
[12/10/2019 8:11:29 PM] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: 'ca4aefed-0190-45d6-9ad6-d22c0cd6abf1'
[12/10/2019 8:11:29 PM] Reading host configuration file 'C:\Users\<redacted>\Desktop\TimerTrigger\host.json'
[12/10/2019 8:11:29 PM] Host configuration file read:
[12/10/2019 8:11:29 PM] {
[12/10/2019 8:11:29 PM] "version": "2.0",
[12/10/2019 8:11:29 PM] "extensionBundle": {
[12/10/2019 8:11:29 PM] "id": "Microsoft.Azure.Functions.ExtensionBundle",
[12/10/2019 8:11:29 PM] "version": "[1.*, 2.0.0)"
[12/10/2019 8:11:29 PM] }
[12/10/2019 8:11:29 PM] }
[12/10/2019 8:11:29 PM] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle
at C:\Users\<redacted>\AppData\Local\Temp\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle
[12/10/2019 8:11:29 PM] Found a matching extension bundle at C:\Users\<redacted>\AppData\Local\Temp\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\1.1.1
[12/10/2019 8:11:29 PM] Fetching information on versions of extension bundle Microsoft.Azure.Functions.ExtensionBundle available on https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/index.json
[12/10/2019 8:11:29 PM] Skipping bundle download since it already exists at path C:\Users\<redacted>\AppData\Local\Temp\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\1.1.1
[12/10/2019 8:11:29 PM] Loading Extention bundle from C:\Users\<redacted>\AppData\Local\Temp\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\1.1.1
[12/10/2019 8:11:29 PM] Reading functions metadata
[12/10/2019 8:11:29 PM] 1 functions found
[12/10/2019 8:11:29 PM] Loading startup extension 'AzureStorage'
[12/10/2019 8:11:29 PM] Loaded extension 'AzureStorage' (3.0.10.0)
[12/10/2019 8:11:30 PM] File 'C:\Program Files\dotnet\dotnet.exe' is not found, 'dotnet' invocation will rely on the PATH environment variable.
[12/10/2019 8:11:30 PM] Initializing Warmup Extension.
[12/10/2019 8:11:30 PM] Initializing Host. OperationId: 'ca4aefed-0190-45d6-9ad6-d22c0cd6abf1'.[12/10/2019 8:11:30 PM] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=ca4aefed-0190-45d6-9ad6-d22c0cd6abf1
[12/10/2019 8:11:30 PM] LoggerFilterOptions
[12/10/2019 8:11:30 PM] {
[12/10/2019 8:11:30 PM] "MinLevel": "None",
[12/10/2019 8:11:30 PM] "Rules": [
[12/10/2019 8:11:30 PM] {
[12/10/2019 8:11:30 PM] "ProviderName": null,
[12/10/2019 8:11:30 PM] "CategoryName": null,
[12/10/2019 8:11:30 PM] "LogLevel": null,
[12/10/2019 8:11:30 PM] "Filter": "<AddFilter>b__0"
[12/10/2019 8:11:30 PM] },
[12/10/2019 8:11:30 PM] {
[12/10/2019 8:11:30 PM] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[12/10/2019 8:11:30 PM] "CategoryName": null,
[12/10/2019 8:11:30 PM] "LogLevel": "None",
[12/10/2019 8:11:30 PM] "Filter": null
[12/10/2019 8:11:30 PM] },
[12/10/2019 8:11:30 PM] {
[12/10/2019 8:11:30 PM] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[12/10/2019 8:11:30 PM] "CategoryName": null,
[12/10/2019 8:11:30 PM] "LogLevel": null,
[12/10/2019 8:11:30 PM] "Filter": "<AddFilter>b__0"
[12/10/2019 8:11:30 PM] }
[12/10/2019 8:11:30 PM] ]
[12/10/2019 8:11:30 PM] }
[12/10/2019 8:11:30 PM] FunctionResultAggregatorOptions
[12/10/2019 8:11:30 PM] {
[12/10/2019 8:11:30 PM] "BatchSize": 1000,
[12/10/2019 8:11:30 PM] "FlushTimeout": "00:00:30",
[12/10/2019 8:11:30 PM] "IsEnabled": true
[12/10/2019 8:11:30 PM] }
[12/10/2019 8:11:30 PM] SingletonOptions
[12/10/2019 8:11:30 PM] {
[12/10/2019 8:11:30 PM] "LockPeriod": "00:00:15",
[12/10/2019 8:11:30 PM] "ListenerLockPeriod": "00:00:15",
[12/10/2019 8:11:30 PM] "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[12/10/2019 8:11:30 PM] "LockAcquisitionPollingInterval": "00:00:05",
[12/10/2019 8:11:30 PM] "ListenerLockRecoveryPollingInterval": "00:01:00"
[12/10/2019 8:11:30 PM] }
[12/10/2019 8:11:30 PM] QueuesOptions
[12/10/2019 8:11:30 PM] {
[12/10/2019 8:11:30 PM] "BatchSize": 16,
[12/10/2019 8:11:30 PM] "NewBatchThreshold": 8,
[12/10/2019 8:11:30 PM] "MaxPollingInterval": "00:00:02",
[12/10/2019 8:11:30 PM] "MaxDequeueCount": 5,
[12/10/2019 8:11:30 PM] "VisibilityTimeout": "00:00:00"
[12/10/2019 8:11:30 PM] }
[12/10/2019 8:11:30 PM] BlobsOptions
[12/10/2019 8:11:30 PM] {
[12/10/2019 8:11:30 PM] "CentralizedPoisonQueue": false
[12/10/2019 8:11:30 PM] }
[12/10/2019 8:11:30 PM] HttpOptions
[12/10/2019 8:11:30 PM] {
[12/10/2019 8:11:30 PM] "DynamicThrottlesEnabled": false,
[12/10/2019 8:11:30 PM] "MaxConcurrentRequests": -1,
[12/10/2019 8:11:30 PM] "MaxOutstandingRequests": -1,
[12/10/2019 8:11:30 PM] "RoutePrefix": "api"
[12/10/2019 8:11:30 PM] }
[12/10/2019 8:11:30 PM] Starting JobHost
[12/10/2019 8:11:30 PM] Starting Host (HostId=desktopl8i1u40-13243865, InstanceId=49bcc245-e949-45fd-b731-1e5ccd7ebbdc, Version=2.0.12888.0, ProcessId=10432, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=~2)
[12/10/2019 8:11:30 PM] Loading functions metadata
[12/10/2019 8:11:30 PM] 1 functions loaded
[12/10/2019 8:11:30 PM] Loading proxies metadata
[12/10/2019 8:11:30 PM] Initializing Azure Function proxies
[12/10/2019 8:11:30 PM] 0 proxies loaded
[12/10/2019 8:11:30 PM] Starting worker process:python c:/Users/<redacted>/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/ptvsd_launcher.py --default --host 127.0.0.1 --port 9091 --wait "C:\Users\<redacted>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.7/WINDOWS/X64/worker.py" --host 127.0.0.1 --port 55800 --workerId 0edae10c-af7f-4e37-8d13-382365306813 --requestId d0d3851a-1ee8-411d-bb74-426ab04b44b6 --grpcMaxMessageLength 134217728
[12/10/2019 8:11:30 PM] python process with Id=13188 started
[12/10/2019 8:11:30 PM] Generating 1 job function(s)
[12/10/2019 8:11:31 PM] Found the following functions:
[12/10/2019 8:11:31 PM] Host.Functions.<functionname>
[12/10/2019 8:11:31 PM]
[12/10/2019 8:11:31 PM] Initializing function HTTP routes
[12/10/2019 8:11:31 PM] No HTTP routes mapped
[12/10/2019 8:11:31 PM]
[12/10/2019 8:11:31 PM] Host initialized (546ms)
[12/10/2019 8:11:31 PM] Executing 'Functions.<functionname>' (Reason='Timer fired at 2019-12-10T15:11:31.5531175-05:00', Id=6176e5d6-c860-4bf7-80e5-712b8919310d)
[12/10/2019 8:11:31 PM] Trigger Details: UnscheduledInvocationReason: RunOnStartup
[12/10/2019 8:12:30 PM] Starting worker process failed
[12/10/2019 8:12:30 PM] The operation has timed out.
[12/10/2019 8:12:31 PM] Starting worker process:python c:/Users/<redacted>/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/ptvsd_launcher.py --default --host 127.0.0.1 --port 9091 --wait "C:\Users\<redacted>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.7/WINDOWS/X64/worker.py" --host 127.0.0.1 --port 55800 --workerId d68b30e0-3146-43f7-92bf-5a8f57ebf3a1 --requestId a4e0053f-b28d-44e1-9671-ac1431349d8e --grpcMaxMessageLength 134217728
[12/10/2019 8:12:31 PM] python process with Id=1524 started
[12/10/2019 8:12:31 PM] Executed 'Functions.<functionname>' (Failed, Id=6176e5d6-c860-4bf7-80e5-712b8919310d)
[12/10/2019 8:12:31 PM] System.Private.CoreLib: Exception while executing function: Functions.<functionname>. Microsoft.Azure.WebJobs.Script: Did not find any initialized language workers.
[12/10/2019 8:12:31 PM] The next 5 occurrences of the '<functionname>' schedule (Cron: '0 30 9 * * *') will be:
[12/10/2019 8:12:31 PM] 12/11/2019 09:30:00-05:00 (12/11/2019 14:30:00Z)
[12/10/2019 8:12:31 PM] 12/12/2019 09:30:00-05:00 (12/12/2019 14:30:00Z)
[12/10/2019 8:12:31 PM] 12/13/2019 09:30:00-05:00 (12/13/2019 14:30:00Z)
[12/10/2019 8:12:31 PM] 12/14/2019 09:30:00-05:00 (12/14/2019 14:30:00Z)
[12/10/2019 8:12:31 PM] 12/15/2019 09:30:00-05:00 (12/15/2019 14:30:00Z)
[12/10/2019 8:12:31 PM]
[12/10/2019 8:12:31 PM] Host started (61122ms)
[12/10/2019 8:12:31 PM] Job host started
Hosting environment: Production
Content root path: C:\Users\<redacted>\Desktop\TimerTrigger
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
[12/10/2019 8:12:36 PM] Host lock lease acquired by instance ID '00000000000000000000000086626BD5'.
[12/10/2019 8:12:37 PM] INFO: Starting Azure Functions Python Worker.
[12/10/2019 8:12:37 PM] INFO: Worker ID: d68b30e0-3146-43f7-92bf-5a8f57ebf3a1, Request ID: a4e0053f-b28d-44e1-9671-ac1431349d8e, Host Address: 127.0.0.1:55800
[12/10/2019 8:12:37 PM] INFO: Successfully opened gRPC channel to 127.0.0.1:55800
[12/10/2019 8:12:37 PM] INFO: Received WorkerInitRequest, request ID a4e0053f-b28d-44e1-9671-ac1431349d8e
[12/10/2019 8:12:37 PM] INFO: Received FunctionLoadRequest, request ID: a4e0053f-b28d-44e1-9671-ac1431349d8e, function ID: 1cf61de1-d4a3-4011-8695-98d4a973f1a9
[12/10/2019 8:12:37 PM] INFO: Successfully processed FunctionLoadRequest, request ID: a4e0053f-b28d-44e1-9671-ac1431349d8e, function ID: 1cf61de1-d4a3-4011-8695-98d4a973f1a9
我遗漏了什么?
更新:
重现了你的错误。
首先,请检查C:\Program Files\dotnet
下是否有dotnet.exe
其次,请检查您的环境变量。
第三,更改settings.json。
{
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": ".venv",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~2",
"debug.internalConsoleOptions": "neverOpen",
"python.pythonPath": ".venv\\Scripts\\python.exe"
}
上图是我的settings.json,如果我没看错的话,我用的是和你一样的设置。
请像这样更改settings.json:
{
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": ".venv",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~2",
"debug.internalConsoleOptions": "neverOpen",
"python.pythonPath": "/path/to/your/venv/bin/python"
}
最终功能可以成功运行并被触发。
原始答案:
尝试找到< code>settings.json文件,
然后,您可以找到这样的文件:
{
"python.pythonPath": "xxxxxxxxx",
...
}
换成
{
"python.pythonPath": "/path/to/your/venv/bin/python",
...
}
我以前遇到过这个错误,但是此设置功能工作正常。
我正在Azure中运行一个Azure函数,该函数由上传到blob存储容器的文件触发。该函数检测到新的blob(文件),但随后输出以下消息-。 设置: 使用Python 3.6.8的Azure函数 在linux机器上运行 使用azure devops构建和部署(用于ci/cd功能) Blob触发函数 我使用相同的blob存储容器、相同的配置值和azure函数的本地实例在本地运行了代码。 函数的核心目
我在Azure上有多个环境,两个作为Windows消费计划,一个作为Linux应用服务计划,部署了相同的代码。 两个环境与Windows消费计划工作正常,Linux应用服务计划显示此错误:“没有找到任何初始化的语言工作者”。部署了相同的代码。当然,我已经将所有配置设置为FUNCTIONS_WORKER_RUNTIME等。
语言辅助函数文件包含一些用于辅助处理语言文件的函数。 加载此辅助函数 此辅助函数使用如下代码加载:$this->load->helper('language'); 下面的函数就可以使用了: lang('language line', 'element id') 此函数使用简单的语法从已加载的语言文件中返回一行文本。这种语法在视图文件中可能比调用 $this->lang->line() 更表意。可选
语言辅助函数文件包含了用于处理语言文件的一些函数。 加载辅助函数 可用函数 加载辅助函数 该辅助函数通过下面的代码加载: $this->load->helper('language'); 可用函数 该辅助函数有下列可用函数: lang($line[, $for = ''[, $attributes = array()]]) 参数: $line (string) -- Language line
我知道这个问题以前有人问过,但请哼我一声。我很难掌握如何初始化一个类。 这是有问题的代码。 我感兴趣的错误是: 我做了建议的更改,现在我得到一个不同的错误:
我对离子框架很陌生 这是我的离子信息: 当我使用' 拜托,我花了很多时间试图解决这个问题,但我解决不了,如果有人知道要解决这个问题,请告诉我。