任何人都可以在此问题上提供帮助,我已经对其进行了数小时的调试,然后结论可能是一个问题,我有一个在Linux Debian上运行的V2功能应用程序,我正在通过VS代码发布代码,但是每当我导入PyoDBC时从门户网站上的功能应用程序中消失,我尝试了不同版本的Python和PY ODBC的不同版本,但该问题不会消失。周围有什么工作吗?
当通过func start触发时,该函数在本地起作用,我也确实将pyodbc添加到我的需求中。txt文件,每当我添加导入pyodbc和发布时,有趣的是,该函数在门户网站上不再可见,部署日志是没有显示任何错误。 我尝试重新启动该函数应用程序,但仍然存在问题,我还通过kudu确认了ODBC已在服务器上安装了函数应用程序正在运行。
I已使用以下代码,并能够用
pyodbc
function_app.py:
import logging
import azure.functions as func
import pyodbc
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="http_trigger", auth_level=func.AuthLevel.ANONYMOUS)
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
try:
Connectionstring = "Driver={ODBC Driver 18 for SQL Server};Server=tcp:{Servername}.database.windows.net,1433;Database={DatabaseName};Uid={Username};Pwd={Password};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;"
with pyodbc.connect(Connectionstring) as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT SYSTEM_USER;")
result = cursor.fetchone()
logging.info('Python HTTP trigger function processed a request.')
logging.info("SYSTEM_USER: %s", result)
return func.HttpResponse(f"SYSTEM_USER: {result}", status_code=200)
except pyodbc.Error as e:
logging.error(f"SQL query failed: {e}")
return func.HttpResponse(f"SQL query failed: {e}")
Quirlements.txt:
azure-functions
pyodbc
部署具有功能高级计划的Azure函数应用程序的功能。 要启用访问,请为IP地址或地址范围添加防火墙规则。
输出:2025-02-14T06:07:36Z [Verbose] AuthenticationScheme: WebJobsAuthLevel was successfully authenticated.
2025-02-14T06:07:36Z [Verbose] AuthenticationScheme: Bearer was not authenticated.
2025-02-14T06:07:36Z [Verbose] Authorization was successful.
2025-02-14T06:07:36Z [Information] Executing 'Functions.http_trigger' (Reason='This function was programmatically called via the host APIs.', Id=0c15334c-621b-4724-b437-a38762ceba1d)
2025-02-14T06:07:36Z [Verbose] Sending invocation id: '0c15334c-621b-4724-b437-a38762ceba1d
2025-02-14T06:07:36Z [Verbose] Posting invocation id:0c15334c-621b-4724-b437-a38762ceba1d on workerId:2a720a46-7c4c-4ffe-aaf7-c3dde50dbc64
2025-02-14T06:07:37Z [Information] Python HTTP trigger function processed a request.
2025-02-14T06:07:37Z [Information] SYSTEM_USER: ('Pravallika',)
2025-02-14T06:07:37Z [Information] Executed 'Functions.http_trigger' (Succeeded, Id=0c15334c-621b-4724-b437-a38762ceba1d, Duration=465ms)