簡體   English   中英

Azure函數Python blobTrigger如何修復“Microsoft.Azure.WebJobs.Extensions.Storage:對象引用未設置為對象的實例。”?

[英]Azure Functions Python blobTrigger How do I fix “Microsoft.Azure.WebJobs.Extensions.Storage: Object reference not set to an instance of an object.”?

使用更詳細的調試輸出更新如下

我以前使用本地開發主機成功運行了Azure Functions。

我最近沒能讓blobTrigger工作。 我采取了以下步驟:

func init NewWave
cd NewWave
func new # -> select httpTrigger called HttpTrigger in language python
func new # -> select blobTrigger called BlobTrigger in language python
func host start

host.json包含:

{
    "version": "2.0",
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    }
}

local.settings.json包含:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "{AzureWebJobsStorage}"
  }
}

AzureWebJobsStorage是通過環境變量設置的連接字符串。

BlobTrigger / function.json包含:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "samples-workitems/{name}",
      "connection": ""
    }
  ]
}

__init__.py包含:

import logging

import azure.functions as func


def main(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")

HttpTrigger加載但BlobTrigger沒有。 輸出是:

Azure Functions Core Tools (2.7.1373 Commit hash: cd9bfca26f9c7fe06ce245f5bf69bc6486a685dd)
Function Runtime Version: 2.0.12507.0
Warning: 'connection' property in '~/NewWave/BlobTrigger/function.json' is empty.
Skipping 'AzureWebJobsStorage' from local settings as it's already defined in current environment variables.
[...]
[6/24/19 12:45:28 PM] Starting JobHost
[...]
[6/24/19 12:45:28 PM] Generating 2 job function(s)
[6/24/19 12:45:28 PM] Found the following functions:
[6/24/19 12:45:28 PM] Host.Functions.HttpTrigger
[6/24/19 12:45:28 PM] Host.Functions.BlobTrigger
[6/24/19 12:45:28 PM]
[6/24/19 12:45:28 PM] Host initialized (280ms)

Http Functions:

    HttpTrigger: [GET,POST] http://localhost:7071/api/HttpTrigger

[6/24/19 12:45:28 PM] A host error has occurred
[6/24/19 12:45:28 PM] Microsoft.Azure.WebJobs.Extensions.Storage: Object reference not set to an instance of an object.
[6/24/19 12:45:28 PM] Stopping JobHost

導致此錯誤的原因是什么?如何解決?

如果需要任何進一步的設置,日志等,請在下面的評論中提出建議,我會更新。

謝謝

操作系統:macOS High Sierra 10.13.6

Python版本:

Python 3.6.8 | Anaconda,Inc。| (默認,2018年12月29日,19:04:46)darwin上的[GCC 4.2.1兼容Clang 4.0.1(標簽/ RELEASE_401 / final)]輸入“help”,“copyright”,“credits”或“license”for更多信息。

pip凍結:

azure == 4.0.0 azure-applicationinsights == 0.1.0 azure-batch == 4.1.3 azure-cognitiveservices-vision-customvision == 1.0.0 azure-common == 1.1.20 azure-cosmosdb-nspkg == 2.0 .2 azure-cosmosdb-table == 1.0.5 azure-datalake-store == 0.0.45 azure-eventgrid == 1.2.0 azure-functions == 1.0.0b4 azure-functions-worker == 1.0.0b8 azure- graphrbac == 0.40.0 azure-keyvault == 1.1.0 azure-loganalytics == 0.1.0 azure-mgmt == 4.0.0 azure-mgmt-advisor == 1.0.1 azure-mgmt-applicationinsights == 0.1.1 azure-mgmt-authorization == 0.50.0 azure-mgmt-batch == 5.0.1 azure-mgmt-batchai == 2.0.0 azure-mgmt-billing == 0.2.0 azure-mgmt-cdn == 3.1.0 azure-mgmt-cognitiveservices == 3.0.0 azure-mgmt-commerce == 1.0.1 azure-mgmt-compute == 4.6.2 azure-mgmt-consumption == 2.0.0 azure-mgmt-containerinstance == 1.4.1 azure-mgmt-containerregistry == 2.8.0 azure-mgmt-containerservice == 4.4.0 azure-mgmt-cosmosdb == 0.4.1 azure-mgmt-datafactory == 0.6.0 azure-mgmt-datalake-analytics == 0.6 .0 azure-mgmt-datalake-nspkg == 3.0.1 azure-mgmt-datalake-store == 0.5.0 azure-mgmt-datamigration == 1 .0.0 azure-mgmt-devspaces == 0.1.0 azure-mgmt-devtestlabs == 2.2.0 azure-mgmt-dns == 2.1.0 azure-mgmt-eventgrid == 1.0.0 azure-mgmt-eventhub == 2.6 .0 azure-mgmt-hanaonazure == 0.1.1 azure-mgmt-iotcentral == 0.1.0 azure-mgmt-iothub == 0.5.0 azure-mgmt-iothubprovisioningservices == 0.2.0 azure-mgmt-keyvault == 1.1 .0 azure-mgmt-loganalytics == 0.2.0 azure-mgmt-logic == 3.0.0 azure-mgmt-machinelearningcompute == 0.4.1 azure-mgmt-managementgroups == 0.1.0 azure-mgmt-managementpartner == 0.1 .0 azure-mgmt-maps == 0.1.0 azure-mgmt-marketplaceordering == 0.1.0 azure-mgmt-media == 1.0.0 azure-mgmt-monitor == 0.5.2 azure-mgmt-msi == 0.2 .0 azure-mgmt-network == 2.7.0 azure-mgmt-notificationhubs == 2.1.0 azure-mgmt-nspkg == 3.0.2 azure-mgmt-policyinsights == 0.1.0 azure-mgmt-powerbiembedded == 2.0 .0 azure-mgmt-rdbms == 1.8.0 azure-mgmt-recoveryservices == 0.3.0 azure-mgmt-recoveryservicesbackup == 0.3.0 azure-mgmt-redis == 5.0.0 azure-mgmt-relay == 0.1 .0 azure-mgmt-reservations == 0.2.1 azure-mgmt-resource == 2.1.0 azure-mgmt-scheduler == 2.0.0 azure-mgmt-search = = 2.0.0 azure-mgmt-servicebus == 0.5.3 azure-mgmt-servicefabric == 0.2.0 azure-mgmt-signalr == 0.1.1 azure-mgmt-sql == 0.9.1 azure-mgmt-storage = = 2.0.0 azure-mgmt-subscription == 0.2.0 azure-mgmt-trafficmanager == 0.50.0 azure-mgmt-web == 0.35.0 azure-nspkg == 3.0.2 azure-servicebus == 0.21.1 azure-servicefabric == 6.3.0.0 azure-servicemanagement-legacy == 0.20.6 azure-storage == 0.36.0 azure-storage-blob == 2.0.1 azure-storage-common == 2.0.0 azure-storage- file == 1.4.0 azure-storage-queue == 1.4.0 msrestazure == 0.6.0

更新

我發現了一些更詳細的日志文件(注意我在macOS上)因此:

2019-06-24T11:14:42.213 [Error] A host error has occurred
System.NullReferenceException : Object reference not set to an instance of an object.
   at Microsoft.Azure.WebJobs.Host.Blobs.Listeners.CloudBlobClientComparer.GetHashCode(CloudBlobClient obj) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\Listeners\CloudBlobClientComparer.cs : 34
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key,TValue value,InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key,TValue value)
   at async Microsoft.Azure.WebJobs.Host.Blobs.Listeners.PollLogsStrategy.RegisterAsync(CloudBlobContainer container,ITriggerExecutor`1 triggerExecutor,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\Listeners\PollLogsStrategy.cs : 74
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Blobs.Listeners.ScanBlobScanLogHybridPollingStrategy.RegisterAsync(CloudBlobContainer container,ITriggerExecutor`1 triggerExecutor,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\Listeners\ScanBlobScanLogHybridPollingStrategy.cs : 61
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Blobs.Listeners.BlobListenerFactory.RegisterWithSharedBlobListenerAsync(String hostId,SharedBlobListener sharedBlobListener,CloudBlobClient blobClient,CloudQueue hostBlobTriggerQueue,IMessageEnqueuedWatcher messageEnqueuedWatcher,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\Listeners\BlobListenerFactory.cs : 155
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Blobs.Listeners.BlobListenerFactory.CreateAsync(CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\Listeners\BlobListenerFactory.cs : 93
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.ListenerFactory.CreateAsync(CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs : 426
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Listeners.HostListenerFactory.CreateAsync(CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Listeners\HostListenerFactory.cs : 62
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Listeners.ListenerFactoryListener.StartAsyncCore(CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Listeners\ListenerFactoryListener.cs : 45
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Listeners.ShutdownListener.StartAsync(CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Listeners\ShutdownListener.cs : 29
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.JobHost.StartAsyncCore(CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs : 101
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Script.ScriptHost.StartAsyncCore(CancellationToken cancellationToken) at C:\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.cs : 241
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Script.WebHost.WebJobsScriptHostService.StartHostAsync(CancellationToken cancellationToken,Int32 attemptCount,JobHostStartupMode startupMode) at C:\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\WebJobsScriptHostService.cs : 163


我建議你在“ connection ”中添加一個值,在你的設置中為空

{
    "scriptFile": "__init__.py",
    "disabled": false,
    "bindings": [
        {
            "name": "myblob",
            "type": "blobTrigger",
            "direction": "in",
            "path": "samples-workitems/{name}",
            "connection":"MyStorageAccountAppSetting"
        }
    ]
}

這是我的local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "mohitsa_STORAGE": ""
  }
}

希望能幫助到你。

通過反復試驗 - 以及一個完全誤導性的錯誤消息......

答案就是將環境變量AzureWebJobsStorage設置為Storage帳戶的主Access密鑰連接字符串,如下所示:

DefaultEndpointsProtocol=https;AccountName=<account name>;AccountKey=<account key>;EndpointSuffix=core.windows.net

而不是通過az storage account generate-sas創建的SAS連接字符串

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM