在Azure函数中不要将库添加到function_app.py

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

I使用以下vs vs代码在VS代码中使用VS代码部署它 enter image description here

noneNETHENTENTH,当我转到函数应用程序门户时,它在功能子菜单下没有显示任何内容:

enter image description here
我不知道为什么我无法在函数应用中看到我的功能,我缺少什么?

在此处是函数的虚拟代码:

F1enter image description here

update

按照@rithwikboj说明,我处于同样的情况。我已经观察到本地我都看不到这些功能:

这是我的

import azure.functions as func import logging import os from azure.identity import DefaultAzureCredential from azure.keyvault.secrets import SecretClient from azure.communication.email import EmailClient from datetime import timezone, timedelta, datetime import jwt import bcrypt import pymssql import json from azure.identity import DefaultAzureCredential from azure.keyvault.secrets import SecretClient app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) @app.route(route="actualizar_contrasena", auth_level=func.AuthLevel.ANONYMOUS) def actualizar_contrasena(req: func.HttpRequest) -> func.HttpResponse: import json try: req_body = req.get_json() username_to_check = req_body.get("username") password_to_check = str(req_body.get("password")) # do things return func.HttpResponse( json.dumps( {"access_token": 1, "refresh_token": 1} ), status_code=200, ) except Exception as e: return func.HttpResponse(str(e), status_code=500)

host.jsonenter image description here 这是我的结构:

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

这是我的要求。txt
root
|_.venv
|_.funcignore
|_host.json
|_function_app.py
|_ local.settings.json

我尝试使用我的github存储库来部署。这是yaml: enter image description hereazure-common==1.1.28 azure-communication-email==1.0.0 azure-core==1.32.0 azure-functions==1.21.3 azure-identity==1.19.0 azure-keyvault-secrets==4.9.0 azure-mgmt-core==1.5.0 bcrypt==4.2.1 certifi==2024.12.14 cffi==1.17.1 charset-normalizer==3.4.1 cryptography==44.0.0 idna==3.10 isodate==0.7.2 jwt==1.3.1 msal==1.31.1 msal-extensions==1.2.0 msrest==0.7.1 oauthlib==3.2.2 portalocker==2.10.1 pycparser==2.22 PyJWT==2.10.1 pymssql==2.3.2 requests==2.32.3 requests-oauthlib==2.0.0 six==1.17.0 typing_extensions==4.12.2 urllib3==2.3.0

i我意识到unignts.txt在函数应用中有问题


文件夹结构尚未更新,因为我一段时间以前删除了readme.md:

enter image description hereupdate 我已经编辑了YAML,现在它可以正确上传。

update2 我删除了除OS,Logging和Azure.Unctions以外的所有导入。之后,我可以正确部署我的功能。但是,当我将enter image description here# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action # More GitHub Actions for Azure: https://github.com/Azure/actions # More info on Python, GitHub Actions, and Azure Functions: https://aka.ms/python-webapps-actions name: Build and deploy Azure Function App - fnc-app-d on: push: branches: - develop workflow_dispatch: env: AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root PYTHON_VERSION: '3.11' # set this to the python version to use (supports 3.6, 3.7, 3.8) jobs: build: runs-on: ubuntu-latest permissions: contents: read #This is required for actions/checkout steps: - name: Checkout repository uses: actions/checkout@v4 - name: Setup Python version uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }} - name: Create and start virtual environment run: | python -m venv venv source venv/bin/activate - name: Install dependencies run: pip install -r requirements.txt # Optional: Add step to run tests here - name: Zip artifact for deployment run: zip -r release.zip function_app.py host.json -x "*.txt venv/*" ".git/*" ".github/* *.md .gitignore local.*" - name: Upload artifact for deployment job uses: actions/upload-artifact@v4 with: name: python-app path: | . !venv/ deploy: runs-on: ubuntu-latest needs: build permissions: id-token: write #This is required for requesting the JWT contents: read #This is required for actions/checkout steps: - name: Download artifact from build job uses: actions/download-artifact@v4 with: name: python-app path: . - name: Unzip artifact for deployment run: unzip -o release.zip - name: Login to Azure uses: azure/login@v2 with: client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_06 }} tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_88510E }} subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_38D5 }} - name: 'Deploy to Azure Functions' uses: Azure/functions-action@v1 id: deploy-to-function with: app-name: 'fnc-app-d' package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} 添加到Python脚本时,它再次消失。我需要在脚本中添加库,这是我的主要问题

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

function_app.py:

import jwt
-local.settings.json:

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()
python azure azure-functions
1个回答
1
投票
Quirlements.txt:

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

-host.json:
azure-functions
pymssql
azure-identity
azure-keyvault-secrets

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

输出:
从VS代码中删除:


部署后:

然后用错误的数据进行了测试以获取500错误:

enter image description here

确保添加所有软件包。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.