簡體   English   中英

Python Azure Function 導入類/模塊時運行不正確

[英]Python Azure Function not correctly running when importing a class/module

我正在嘗試在 Python 中運行 Azure Function 並且需要從模塊中導入 class。 看來function只運行了class,並沒有運行程序的rest。 class 登錄網站,將 csv 轉換為 dataframe,並返回 dataframe。我研究了文件夾結構,看來我正在正確執行所有步驟。 該模塊位於一個名為 shared_code 的文件夾中,function 位於另一個名為 Intelie_Alerts 的文件夾中(我已嘗試絕對導入和相對導入)。有關如何使此 function 正常運行的任何幫助。 我期待導入模塊,運行 class,然后清理 dataframe 並發送到數據庫。function 沒有失敗,但我沒有收到任何發送到數據庫的信息。

在此處輸入圖像描述 在此處輸入圖像描述

import azure.functions as func
from shared_code.Intelie_Creds import Intelie


def main(mytimer: func.TimerRequest) -> None:

    intel = Intelie()
    byte_stream = intel.csv_custom()





File Structure:
 <project_root>/
 | - .venv/
 | - .vscode/
 | - Intelie_Alerts/
 | | - __init__.py
 | | - function.json
 | - shared_code/
 | | - __init__.py
 | | - Intelie_Creds.py
 | | - function.json

從我這邊復制后,這是按預期工作的。 由於 function 沒有失敗,您收到的原因之一可能是您正在使用的觸發器。 默認情況下,計時器觸發器的 cron 表達式為0 */5 * * * *需要時間來觸發 function。上面的 cron 表達式每天在每小時的第 5 分鍾觸發一次。 我建議您更改 cron 表達式並檢查是否相同。

出於演示目的,我已將 Timer Trigger 替換為 HTTP trigger 並進行檢查並獲得預期結果。 下面是我正在使用的 function。

import logging

import azure.functions as func
from shared_code.Intelie_Creds import Intelie

def main(req: func.HttpRequest) -> func.HttpResponse:
    intel = Intelie()
    print(intel)
    return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

結果:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM