微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何调用可在localhost上运行的azure函数并在azure门户上返回500?

如何解决如何调用可在localhost上运行的azure函数并在azure门户上返回500?

我在VSCode中使用Python创建了一个Azure函数。该API包含对AzureWebJob的访问权限,当我在本地主机http:// localhost:7071 / api / FUNCTIONNAME?Param1 = value1中对其进行测试时,响应为200,并且JSON返回正常,但是,当我将该函数部署到Azure链接https://APPSERVICENAME.azurewebsites.net/api/FUNCTIONNAME?code=APICODE==&Param1=value1返回500 Internal Server Error。

我正在使用Postman进行测试并在Chrome上答复了该查询

使用的代码是:

import logging
import azure.functions as func
from io import StringIO
import pandas as pd
from datetime import datetime as dt
import json

#filter the dataframe
def filter(pdf,keys,daterange):
  jkeys=[]
  for key in keys:
    #filter by numeric key
    if(reg.isdigit()):
      jkeys.append(int(key))
  #filtering by two types of keys
  pdfA=pdf[pdf['key'].isin(keys)]
  pdfS=pdf[pdf['numerickey'].isin(jkeys)]
  #concat the DFs
  pdf=pd.concat([pdfS,pdfA],axis=0)
  #Filtering by a daterange or single date
  if(daterange.isdigit()): 
    pdf=pdf[pdf['Day']==int(daterange)]
    return pdf
  else:
    #getting the two dates
    date=daterange.split('-')
    #filtering the rows
    pdf=pdf[(pdf['Day']>=int(date[0])) & (pdf['Day']<=int(date[1]))]
    return pdf

# function to validate the params
def param_validation(param: str,param_name: str,req: func.HttpRequest) -> str:
                    
    if not param:
        try:
            req_body = req.get_json()
        except ValueError:

            if param != None and '-' in param:
                return func.HttpResponse(
                    "Set a date in the query",status_code=400
                )
        else:
            param = req_body.get(param_name)
            return param
    else:
        return param

def main(req: func.HttpRequest,inputBlob: func.InputStream) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    #get the params
    daterange = req.params.get('daterange')
    keys = req.params.get('keys')
    name=req.params.get('name')

    daterange = param_validation(daterange,'daterange',req)
    keys = param_validation(keys,'keys',req)

    #this condition is included just to test fast if works 
    if name:
        return func.HttpResponse(f"Hello {name}!")
    #This is to get the real data request function
    if daterange and (keys):
        try:
            
            if daterange and keys:
                # get the data from a csv in the datalake 
                data = pd.read_csv(StringIO(inputBlob.read().decode('utf-8')))
                keys=keys.split(',')  
                dfFilt=filter(data,daterange).fillna(0)

                return func.HttpResponse(f"{json.dumps(dfFilt.to_dict(orient='record'))}")

            else:
                return func.HttpResponse(
                    "insert a valid daterange to the query",status_code=400
            )
        except:
                return func.HttpResponse(
                    "Params are wrong.",status_code=500
            )
    else:
            return func.HttpResponse(
                "Params missed",status_code=400
            )
          

目的是从datalake中获取csv并返回由提供的2个args过滤的行。

我发现了有关该错误的更多信息,平台返回了 137个python代码。我使用了过时的csv(即更轻的60mb)部署了最后一个功能性api,并且该api运作良好。但是,当我设置新的csv(300mb)时,api开始返回代码500内部服务器错误

我认为这只是内存问题,因为在本地主机上运行正常。

是从datalake获取数据的另一种方法,使用azure函数过滤两列?还是有可能解决此内存问题?

谢谢!

解决方法

此问题可能由多种原因引起,因此请显示更多详细信息。在我这边,没问题。

1,参数代码应该是函数的键(如果不是匿名的话)。

2,请检查您的代码,也许您使用的是不存在的内容。(请显示您的代码和其他文件。)

您可以使用应用程序数据分析来检查详细信息错误,也可以直接查看日志文件:

转到https://yourfunctionappname.scm.azurewebsites.net/DebugConsole,然后单击到LogFiles\Application\Functions\Function\HttpTrigger1>,您将在其中找到日志文件,单击并检查错误。

任何更新,请让我知道。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。