我部署了一个天蓝色函数,它给出了此异常,如下所示:
Unable to reload azure.functions. Using default. Exception: cannot import name 'BlobSource' from 'azure.functions.decorators' (/azure-functions-host/workers/python/3.9/LINUX/X64/azure/functions/decorators/init.py)
我通过以下 yml 文件部署 azure 功能:
name: Deploy Python project to Azure Function App
on:
push:
branches: ["main"]
env:
AZURE_FUNCTIONAPP_NAME: 'my-function-name'
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.'
PYTHON_VERSION: '3.9'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest --disable-warnings
build-and-deploy:
runs-on: ubuntu-latest
needs: test
if: ${{ needs.test.result == 'success' }}
environment: dev
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4
- name: Setup Python ${{ env.PYTHON_VERSION }} Environment
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: 'Resolve Project Dependencies Using Pip'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
python -m pip install --upgrade pip
pip install -r requirements.txt --target=".python_packages/lib/site-packages"
popd
- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }} # Remove publish-profile to use Azure RBAC
scm-do-build-during-deployment: true
enable-oryx-build: true
需求.txt
azure-functions==1.20.0
pandas==2.2.2
pydantic==2.8.2
pydantic_core==2.20.1
pytest==8.3.2
pytest-asyncio==0.23.8
requests==2.32.3
运行版本:4 蟒蛇版本:3.9
我试图找出可能导致此异常的原因,但该异常是持久的。
任何帮助将不胜感激!
检查.venv/Lib/Site-packages/azure/functions/decorators/init.py
下是否有
BlobSource:
from .core import Cardinality, AccessRights
from .function_app import FunctionApp, Function, DecoratorApi, DataType, \
AuthLevel, Blueprint, ExternalHttpFunctionApp, AsgiFunctionApp, \
WsgiFunctionApp, FunctionRegister, TriggerApi, BindingApi, \
SettingsApi, BlobSource
from .http import HttpMethod
__all__ = [
'FunctionApp',
'Function',
'FunctionRegister',
'DecoratorApi',
'TriggerApi',
'BindingApi',
'SettingsApi',
'Blueprint',
'ExternalHttpFunctionApp',
'AsgiFunctionApp',
'WsgiFunctionApp',
'DataType',
'AuthLevel',
'Cardinality',
'AccessRights',
'HttpMethod',
'BlobSource'
]
我已使用
requirements.txt
中的模块创建了一个 Python Azure 函数,并且能够使用 GitHub 操作将该函数部署到 Azure。
需求.txt:
azure-functions==1.20.0
pandas==2.2.2
pydantic==2.8.2
pydantic_core==2.20.1
pytest==8.3.2
pytest-asyncio==0.23.8
requests==2.32.3
工作流程:
name: Build and deploy Python project to Azure Function App - appname
on:
push:
branches:
- main
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.9' # set this to the python version to use (supports 3.6, 3.7, 3.8)
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python version
uses: actions/setup-python@v1
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 release.zip ./* -r
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: python-app
path: |
release.zip
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-function.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: python-app
- name: Unzip artifact for deployment
run: unzip release.zip
- name: 'Deploy to Azure Functions'
uses: Azure/functions-action@v1
id: deploy-to-function
with:
app-name: 'appname'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_8212BBXXXD0E6 }}
scm-do-build-during-deployment: true
enable-oryx-build: true
GitHub 中的部署状态: