【问题标题】:Blob Trigger for Python Function App is not FiringPython 函数应用程序的 Blob 触发器未触发
【发布时间】:2019-08-03 19:09:09
【问题描述】:

我正在使用 Ubuntu 16.04.5 LTS 本地计算机使用 CLI 和 Azure Functions Core Tools (Ref) 创建 Python Function App 并将其发布到 Azure。我已经配置了 Blob 触发器,我的 function.json 文件如下所示:

{
"disabled": false,
"scriptFile": "__init__.py",
"bindings": [
{
  "name": "<Blob Trigger Name>",
  "type": "blobTrigger",
  "direction": "in",
  "path": "<Blob Container Name>/{name}",
  "connection": "<Connection String having storage account and key>"
},
{
  "name": "outputblob",
  "type": "blob",
  "path": "<Blob Container Name>",
  "connection": "<Connection String having storage account and key>",
  "direction": "out"
}
]
}

我的 init.py 函数如下所示。

def main(<Blob Trigger Name>: func.InputStream, doc: func.Out[func.Document]):
logging.info(f"Python blob trigger function processed blob \n"
             f"Name: {<Blob Trigger Name>.name}\n"
             f"Blob Size: {<Blob Trigger Name>.length} bytes")
logging.basicConfig(filename='example.log',level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')

# Write text to the file.
file = open("QuickStart.txt",  'w')
file.write("Hello, World!")
file.close()

# Create the BlockBlockService that is used to call the Blob service for the storage account
block_blob_service = BlockBlobService(account_name='<Storage Account Name>', account_key='<Storage Account Key>')
container_name='<Blob Container Name>'

# Set the permission so the blobs are public.
block_blob_service.set_container_acl(container_name, public_access=PublicAccess.Container)

# Upload the created file, use local_file_name for the blob name
block_blob_service.create_blob_from_path(container_name, 'QuickStart.txt', '')

Function App 是“始终开启”,但是当我在存储中上传 blob 时,该功能没有被触发。另一个参考链接是这个(Ref).

怎么了?

感谢和问候, 沙申克

【问题讨论】:

  • 您的 Function 主机日志(而不是您自己的 example.log 日志)是什么样的?
  • 没有遇到与您相同的问题,但我遇到了这个 SO 帖子,因为我的功能没有被触发。将 "path": "/" 替换为 "path": "/{name}" 为我解决了这个问题。

标签: python function azure blob azure-triggers


【解决方案1】:

您是否检查过 local.settings.json(存储帐户的连接字符串)也在 Azure 的函数应用中?默认情况下,它们从本地计算机发布。

您可以在门户中手动配置它们或使用 publish-local-settings 标志:

func azure functionapp publish "functionname" --publish-local-settings

【讨论】:

    【解决方案2】:

    我尝试通过使用带有默认模板的 Visual Studio 代码在 python 中创建示例函数应用程序来重现此问题,并最终部署在 Linux 中。它对我有用。

    这是我在 pyhton 文件中编写的一段代码。

    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")
    

    这是我的函数应用中的 function.json 文件。

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

    我正在使用 2.0 Azure 函数、python 3.6 和 Azure Functions Core Tools 2.2.70 版

    这是我使用的参考链接:

    https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python

    请尝试使用它,看看是否有帮助。

    【讨论】:

      【解决方案3】:

      在您的 py 脚本的主定义中,您有 doc 的第二个参数:func.Out[func.Document],它用于 cosmos db。这应该是一个输出流,因为它的类型是 blob

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-02-26
        • 2020-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-21
        • 2022-01-08
        相关资源
        最近更新 更多