admin管理员组

文章数量:1291263

can anyone help with this issue, I have debugged it for hours before concluding it might be an issue, I have a v2 function app running on Linux Debian, I am publishing my code via vs code but when ever I import pyodbc the function would disappear from function app on the portal, I tried different version of python and different version of py odbc for 2 days this issue won’t go away. Is there any work around?

The function works locally when triggered via func start, and i also do have pyodbc added to my requirement.txt file, what's funny is whenever i add import pyodbc and publish, the function is not visible on the portal anymore and the deployment log is not showing any error.

I have tried restarting the function app but still issue persist, i also confirmed via Kudu that ODBC is installed on the server the function app is running from.

can anyone help with this issue, I have debugged it for hours before concluding it might be an issue, I have a v2 function app running on Linux Debian, I am publishing my code via vs code but when ever I import pyodbc the function would disappear from function app on the portal, I tried different version of python and different version of py odbc for 2 days this issue won’t go away. Is there any work around?

The function works locally when triggered via func start, and i also do have pyodbc added to my requirement.txt file, what's funny is whenever i add import pyodbc and publish, the function is not visible on the portal anymore and the deployment log is not showing any error.

I have tried restarting the function app but still issue persist, i also confirmed via Kudu that ODBC is installed on the server the function app is running from.

Share Improve this question asked Feb 13 at 15:04 TinTin 1 2
  • Provide your function code and requirements.txt. – Pravallika KV Commented Feb 14 at 3:32
  • Check if below answer helps @Tin. – Pravallika KV Commented Feb 18 at 4:39
Add a comment  | 

1 Answer 1

Reset to default 0

I have used below code and able to deploy the function with pyodbc module to Azure function App.

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,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}")  

requirements.txt:

azure-functions
pyodbc

Deploy the function to Azure function App with Functions premium plan.

To enable access, add a firewall rule for the IP address or address range.

Output:

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)

本文标签: pythonPyodbc does not work on Linux based az function appStack Overflow