【问题标题】: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 Python blobTrigger 如何修复“Microsoft.Azure.WebJobs.Extensions.Storage:对象引用未设置为对象的实例。”?
【发布时间】:2019-11-06 06:59:06
【问题描述】:

下面更新更详细的调试输出

我过去曾使用本地开发主机成功运行 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

是什么导致了这个错误,我该如何解决?

如果需要任何进一步的设置、日志等,请在下面的 cmets 中告知,我会更新。

谢谢

操作系统:macOS High Sierra 10.13.6

Python 版本:

Python 3.6.8 |Anaconda, Inc.| (默认,2018 年 12 月 29 日,19:04:46) [GCC 4.2.1 兼容的 Clang 4.0.1 (tags/RELEASE_401/final)] 在 darwin 输入“help”、“copyright”、“credits”或“license”了解更多信息。

点冻结:

天蓝色==4.0.0 天蓝色应用洞察==0.1.0 天蓝色批处理==4.1.3 azure-cognitiveservices-vision-customvision==1.0.0 天蓝色常用==1.1.20 天蓝色 cosmosdb-nspkg==2.0.2 天蓝色 cosmosdb 表==1.0.5 天蓝色数据湖商店==0.0.45 天蓝色事件网格==1.2.0 天蓝色函数==1.0.0b4 天蓝色功能工人==1.0.0b8 天蓝色graphrbac==0.40.0 天蓝色密钥库==1.1.0 天蓝色loganalytics==0.1.0 天蓝色mgmt==4.0.0 天蓝色管理顾问==1.0.1 azure-mgmt-applicationinsights==0.1.1 azure-mgmt-授权==0.50.0 天蓝色管理批处理==5.0.1 天蓝色mgmt-batchai==2.0.0 天蓝色管理计费==0.2.0 天蓝色mgmt-cdn==3.1.0 azure-mgmt-cognitiveservices==3.0.0 天蓝色管理商务==1.0.1 天蓝色管理计算==4.6.2 天蓝色管理消耗==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 天蓝色mgmt-dns==2.1.0 天蓝色mgmt-eventgrid==1.0.0 天蓝色mgmt-eventhub==2.6.0 天蓝色-mgmt-hanaonazure==0.1.1 azure-mgmt-iotcentral==0.1.0 天蓝色mgmt-iothub==0.5.0 azure-mgmt-iothubprovisioningservices==0.2.0 azure-mgmt-keyvault==1.1.0 azure-mgmt-loganalytics==0.2.0 天蓝色管理逻辑==3.0.0 azure-mgmt-machinelearningcompute==0.4.1 azure-mgmt-managementgroups==0.1.0 azure-mgmt-managementpartner==0.1.0 天蓝色mgmt-maps==0.1.0 azure-mgmt-marketplaceordering==0.1.0 天蓝色管理媒体==1.0.0 天蓝色管理监视器==0.5.2 天蓝色mgmt-msi==0.2.0 天蓝色管理网络==2.7.0 azure-mgmt-notificationhubs==2.1.0 天蓝色mgmt-nspkg==3.0.2 azure-mgmt-policyinsights==0.1.0 azure-mgmt-powerbiembedded==2.0.0 天蓝色-mgmt-rdbms==1.8.0 azure-mgmt-recoveryservices==0.3.0 azure-mgmt-recoveryservicesbackup==0.3.0 天蓝色-mgmt-redis==5.0.0 天蓝色管理中继==0.1.0 azure-mgmt-reservations==0.2.1 天蓝色管理资源==2.1.0 天蓝色管理调度程序==2.0.0 天蓝色管理搜索==2.0.0 天蓝色管理服务总线==0.5.3 azure-mgmt-servicefabric==0.2.0 天蓝色mgmt-signalr==0.1.1 天蓝色mgmt-sql==0.9.1 天蓝色管理存储==2.0.0 天蓝色管理订阅==0.2.0 azure-mgmt-trafficmanager==0.50.0 天蓝色mgmt-web==0.35.0 天蓝色-nspkg==3.0.2 天蓝色服务总线==0.21.1 天蓝色服务结构==6.3.0.0 azure-servicemanagement-legacy==0.20.6 天蓝色存储==0.36.0 天蓝色存储 blob==2.0.1 天蓝色存储通用==2.0.0 天蓝色存储文件==1.4.0 天蓝色存储队列==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


【问题讨论】:

    标签: python azure azure-functions azure-blob-storage azure-functions-core-tools


    【解决方案1】:

    通过反复试验 - 以及完全误导性的错误消息...

    答案是简单地将环境变量AzureWebJobsStorage 设置为存储帐户的主访问密钥连接字符串,如下所示:

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

    而不是通过az storage account generate-sas创建的SAS连接字符串

    【讨论】:

      【解决方案2】:

      我建议您在设置中为空的“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": ""
        }
      }
      

      希望对你有帮助。

      【讨论】:

      • 非常感谢回复 - 但还没有......我已经向 function.json 添加了一个连接字符串。请你能拼出你的 local.settings.json 值参数吗?你的 host.json 是什么样的?谢谢!
      • 在使用本地开发主机之前需要注册应用程序吗?我认为不是因为 httpTrigger 有效 - 还是我错了?谢谢
      • 我会检查并返回。如果你能分享代码库就好了,我很容易复制。
      • 它指向我自己的 Azure Blob 存储 - 我应该编辑它吗?
      • 你是说 Python blobTrigger 适合你吗??
      猜你喜欢
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 1970-01-01
      相关资源
      最近更新 更多