发布后Azure函数导入Pyodbc错误

时间:2019-11-22 14:41:42

标签: azure azure-functions

首先-非常感谢您的所有帖子和回复,这极大地帮助了我!

我已经成功创建了一个Azure函数,该函数具有导入的pyodbc,azure.function,如下所示。

*import logging
import pyodbc
import json
import azure.functions as func
def main(req: func.HttpRequest) ->  func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    try:*

它在VS Code中工作正常,但是当我尝试在发布后运行它时,它会失败并显示

**2019-11-22T14:31:17.743 [Information] Executing 'Functions.godataexcelautomation' (Reason='This function was programmatically called via the host APIs.', Id=79cebf6c-b371-4a12-b623-16931abe7757)
2019-11-22T14:31:17.761 [Error] Executed 'Functions.godataexcelautomation' (Failed, Id=79cebf6c-b371-4a12-b623-16931abe7757)
Result: Failure
Exception: ModuleNotFoundError: No module named 'pyodbc'
Stack:   File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/dispatcher.py", line 242, in _handle__function_load_request
    func_request.metadata.entry_point)
  File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/loader.py", line 66, in load_function
    mod = importlib.import_module(fullmodname)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/site/wwwroot/godataexcelautomation/__init__.py", line 2, in <module>
    import pyodbc**

感谢您可以提供的任何帮助..好像我需要将pyodbc用于Azure门户?在.json文件中? 预先感谢!

1 个答案:

答案 0 :(得分:0)

当我直接从VS代码部署python函数时,发生了与您相同的错误。请检查您是否在pyobdc中添加了requirements.txt并尝试以下命令来部署python函数,它解决了我的问题:

func azure functionapp publish <APP_NAME> --build remote

顺便说一句,您应该在Python函数上将ODBC Driver 17 for SQL Server定义为odbc驱动程序。

结果: enter image description here