python3不再适用于Azure功能

时间:2017-10-26 17:13:59

标签: python azure azure-functions

我的功能运行了一段时间但突然间什么都没有了。我按照https://prmadi.com/running-python-code-on-azure-functions-app/中的说明成功完成了操作。代码是从Github自动部署的。然而,几周前出了问题。我还没有解决我的问题,但我已经想出了一些事情:

1)我安装的模块(使用pip)已经消失或无法再找到。我设法安装它们,但它们会在几个小时内消失。

2)该功能运行2.7。我想这是因为PATH已经改变了。以前\ home \ site \ tools就在路径中。这已不再是这种情况。之前的工作是使用nuget site-extension安装python 3,然后将其移动到\ home \ site \ tools文件夹。我试图将python3安装移到例如路径中的/ home / site / deployments / tools。

更新:我尝试使用此处的说明:https://lnx.azurewebsites.net/python-3-6-deployments-on-azure-function-apps/。我设法让我的函数运行python 3,我设法让Azure安装所需的模块。所以简而言之,我有以下文件夹结构:

requirements.txt
├── function
    ├── deploy.cmd
    ├── .deployment
    ├── function.json
    ├── run.py

部署

@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off

:: --------------------------------------------------------
:: KUDU Deployment Script for Python 3.6 on Azure Functions
:: Version: 0.1
:: --------------------------------------------------------

:: Prerequisites
:: -------------

:: Verify node.js installed
where node 2>nul >nul
IF %ERRORLEVEL% NEQ 0 (
  echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
  goto error
)

:: Setup
:: -----

setlocal enabledelayedexpansion

SET ARTIFACTS=%~dp0%..\artifacts

IF NOT DEFINED DEPLOYMENT_SOURCE (
  SET DEPLOYMENT_SOURCE=%~dp0%.
)

IF NOT DEFINED DEPLOYMENT_TARGET (
  SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
)

IF NOT DEFINED NEXT_MANIFEST_PATH (
  SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest

  IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
    SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
  )
)

IF NOT DEFINED KUDU_SYNC_CMD (
  :: Install kudu sync
  echo Installing Kudu Sync
  call npm install kudusync -g --silent
  IF !ERRORLEVEL! NEQ 0 goto error

  :: Locally just running "kuduSync" would also work
  SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd
)
goto Deployment

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------

:Deployment
echo Handling python deployment.

:: 1. KuduSync
IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" (
  call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
  IF !ERRORLEVEL! NEQ 0 goto error
)

IF NOT EXIST "%DEPLOYMENT_TARGET%\requirements.txt" goto postPython
IF EXIST "%DEPLOYMENT_TARGET%\.skipPythonDeployment" goto postPython

echo Detected requirements.txt.  You can skip Python specific steps with a .skipPythonDeployment file.


pushd "%DEPLOYMENT_TARGET%"

:: 2. Create virtual environment
IF NOT EXIST "D:\home\site\tools\python36*" (

  echo Creating Python 3.6.1 x64 virtual environment...
  nuget.exe install -Source https://www.siteextensions.net/api/v2/ -OutputDirectory D:\home\site\tools python361x64
  mv /d/home/site/tools/python3*/content/python*/* /d/home/site/tools/
  IF !ERRORLEVEL! NEQ 0 goto error

) ELSE (
  echo Found compatible virtual environment.
)

:: 3. Install packages
echo Pip install requirements...
D:\home\site\tools\python.exe -m pip install -r "%DEPLOYMENT_TARGET%\requirements.txt"
IF !ERRORLEVEL! NEQ 0 goto error

popd

:postPython

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto end

:: Execute command routine that will echo out when error
:ExecuteCmd
setlocal
set _CMD_=%*
call %_CMD_%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
exit /b %ERRORLEVEL%

:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul

:exitSetErrorLevel
exit /b 1

:exitFromFunction
()

:end
endlocal
echo Finished successfully.

这实际上有效,但过了一段时间我要么1)回到python 2.7并没有包或我收到错误信息

Exception while executing function: Functions.toc
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.toc ---> System.ApplicationException
   at async Microsoft.Azure.WebJobs.Script.Description.ScriptFunctionInvoker.ExecuteScriptAsync(String path,String arguments,Object[] invocationParameters,FunctionInvocationContext context) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Description\Script\ScriptFunctionInvoker.cs : 114
   at async Microsoft.Azure.WebJobs.Script.Description.ScriptFunctionInvoker.InvokeCore(Object[] parameters,FunctionInvocationContext context) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Description\Script\ScriptFunctionInvoker.cs : 55
   at async Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Description\FunctionInvokerBase.cs : 95
   at async Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker`2.InvokeAsync[TReflected,TReturnType](TReflected instance,Object[] arguments)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync[TReflected,TReturnValue](Object instance,Object[] arguments)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,ParameterHelper parameterHelper,TraceWriter traceWriter,CancellationTokenSource functionCancellationTokenSource)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)
   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) 
   End of inner…

尽管如此我可以打开控制台并运行代码而不会出错。所以我尝试重新部署该功能,但没有运气。我想azure会在某些时间间隔运行一些清理工作?

最佳

1 个答案:

答案 0 :(得分:0)

问题解决了。它是由Azure https://github.com/Azure/azure-webjobs-sdk-script/issues/1758

中的错误引起的

基本上只需在"功能应用设置"中回滚到旧版本(例如1.0.11296)一切都有效:-)