从 VS Code 部署后,Azure 门户功能应用程序不显示功能

问题描述 投票:0回答:1

例如我有这个功能

enter image description here

我使用 VS Code 中的以下

F1
选项通过 VS Code 部署它 enter image description here

尽管如此,当我转到函数应用程序门户时,它在函数子菜单下没有显示任何内容: enter image description here

我不知道为什么我无法在函数应用程序中看到我的函数,我错过了什么?

这是该函数的虚拟代码:

import azure.functions as func
import logging
import pymssql
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
from datetime import datetime, timedelta
import json
import jwt

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.route(
    route="actualizar_contrasena", methods=["POST"], auth_level=func.AuthLevel.ANONYMOUS
)
def actualizar_contrasena(req: func.HttpRequest) -> func.HttpResponse:
   
    try:
        # Establece la conexión
        conn = pymssql.connect(X, XX, XXX, XXXX)
        cursor = conn.cursor()
        email = auth_token.get("email")
        
        if email and password:
            # do things
        else:
            return func.HttpResponse(f"Error", status_code=500)

    except Exception as e:
        logging.error(f"Error: {e}")
        return func.HttpResponse(f"Error: {e}", status_code=500)
    finally:
        if "conn" in locals() and conn:
            conn.close()

    return func.HttpResponse(
        "Elemento eliminado correctamente",
        status_code=200,
    )
python azure azure-functions
1个回答
0
投票

我使用了下面的代码,它已为我部署并遵循以下过程:

function_app.py:

import azure.functions as func
import logging as ri_lg
import pymssql as chop
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient

rith = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@rith.route(
    route="rith_func", methods=["POST"], auth_level=func.AuthLevel.ANONYMOUS
)
def rith_func(req: func.HttpRequest) -> func.HttpResponse:
    try:
        rith_rq_bdy = req.get_json()
        eml = rith_rq_bdy.get("email")
        pwd = rith_rq_bdy.get("password")
        ri_con = chop.connect(server="rithwik.database.windows.net",user="rithwik",password="RTestpass@2",database="test1")
        cho_cur = ri_con.cursor()
        cho_cur.execute("UPDATE users SET password = %s WHERE email = %s",(pwd, eml))
        ri_con.commit()

        return func.HttpResponse("Hello Rithwik, the Password has been updated",status_code=200)

    except Exception as f:
        ri_lg.error(f"Error: {f}")
        return func.HttpResponse(f"Hello Rithwik, there is an error: {f}",status_code=500)
    finally:
        if "ri_con" in locals() and ri_con:
            ri_con.close()

local.settings.json:

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

需求.txt:

azure-functions
pymssql
azure-identity
azure-keyvault-secrets

主机.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

结构:

RithAppFolder
├── __ pycache __
├── .venv
├── .vscode
├── .funcignore
├── .gitignore
├── function_app.py
├── host.json
├── local.settings.json
└── requirements.txt

输出:

从 VS Code 部署:

enter image description here

部署后:

enter image description here

然后用错误的数据进行测试,得到500错误:

enter image description here

确保添加所有包。

© www.soinside.com 2019 - 2024. All rights reserved.