You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Python HTTPTrigger发Event Grid事件遇401授权头缺失错误

Azure Python HTTPTrigger函数向Event Grid主题发送事件时遭遇401未授权错误

No authorization header in the request. Report '59dda51f-8df1-40ed-ac10-fc50cc9ec807:0:5/29/2023 1:04:46 AM (UTC)' to our forums for assistance or raise a support ticket. Status: 401 (No authorization header in the request. Report '59dda51f-8df1-40ed-ac10-fc50cc9ec807:0:5/29/2023 1:04:46 AM (UTC)' to our forums for assistance or raise a support ticket.) ErrorCode: Unauthorized Content: { "error": { "code": "Unauthorized", "message": "No authorization header in the request. Report '59dda51f-8df1-40ed-ac10-fc50cc9ec807:0:5/29/2023 1:04:46 AM (UTC)' to our forums for assistance or raise a support ticket.", "details": [{ "code": "Unauthorized", "message": "No authorization header in the request. Report '59dda51f-8df1-40ed-ac10-fc50cc9ec807:0:5/29/2023 1:04:46 AM (UTC)' to our forums for assistance or raise a support ticket." }] } } Headers: Server: Microsoft-HTTPAPI/2.0 Strict-Transport-Security: REDACTED x-ms-request-id: 59dda51f-8df1-40ed-ac10-fc50cc9ec807 Date: Mon, 29 May 2023 01:04:46 GMT Connection: close Content-Length: 517 Content-Type: application/json; charset=utf-8

已完成的匿名配置

  • Event Grid主题:身份标识关闭,本地认证已禁用
  • Azure函数为匿名HTTP触发器
  • 已验证ENDPOINT和ACCESS KEY正确无误

HTTP Trigger代码(init.py)

import logging
import datetime
import os
import azure.functions as azfunc

def main( req: azfunc.HttpRequest
              , outputEvent: azfunc.Out[azfunc.EventGridOutputEvent]
              ) -> azfunc.HttpResponse:
    logging.info(f"\nENDPOINT: {os.environ.get('EVENT_GRID_TOPIC_ENDPOINT')}")
    logging.info(f"\nKEY: {os.environ.get('EVENT_GRID_TOPIC_KEY')}")

    event = azfunc.EventGridOutputEvent (
            id="1234",
            data={"tag1": "value1", "tag2": "value2"},
            subject="test-subject",
            event_type="test-event-1",
            event_time=datetime.datetime.utcnow(),
            data_version="1.0"
        )
    outputEvent.set(event)
    return azfunc.HttpResponse( body=f'Event Sent... {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}', status_code=200 )

functions.json配置

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ],
      "route": "{*routes}"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    },
    {
      "type": "eventGrid",
      "name": "outputEvent",
      "topicEndpointUri": "EVENT_GRID_TOPIC_ENDPOINT",
      "topicKeySetting": "EVENT_GRID_TOPIC_KEY",
      "direction": "out"
    }
  ]
} 

已尝试多种发送方式,包括使用EventGridPublisherClient(仅本地运行有效,部署到Azure函数后无效),也尝试启用托管标识但尚未深入研究。认为当前配置应无需认证即可运行,寻求开发者帮助。

内容的提问来源于stack exchange,提问作者Tobbi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 10:20:37