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

部署与本地主机后运行时,http 触发 Azure 函数在 python 中错误

如何解决部署与本地主机后运行时,http 触发 Azure 函数在 python 中错误

首先让您知道我对此很陌生,所以请原谅我的无知。

我想创建一个触发的 azure 函数,该函数通过现有 API 使用数据。 我写的代码是用 Python 写的。

我在下面的 Visual Studio 代码中创建了一个 http 触发的 azure 函数

import logging
import azure.functions as func
import http.client
import json
import pandas as pd
import numpy as np 
import pyodbc
from datetime import datetime

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


    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name=='example':
      
      # Extracting the dataset size for each resource
      size_= 0
      from_= 0
      creationdatetime_= '2000-01-01'

      conn = http.client.HTTPSConnection("*****.api.******.com") # This is the http that I want to consume the data from
      payload = ''
      headers = {               
          'Authorization': 'Basic **********','Cookie': '***************'
                }

      conn.request("GET","/*****/******?size={}&from={}&creationdatetime={}".format(size_,from_,creationdatetime_),payload,headers)
      res = conn.getresponse()
      data = res.read()
      #The_Resource=data.decode("utf-8")
      #The_Resource=json.loads(data) # Converting JSON string to dictionary
      #total               =  The_Resource['total']
  

      return func.HttpResponse(data)
  
    else:
      return func.HttpResponse("Wrong 'name' key parameter entered.Please check the name and run again.",status_code=200)

当我用本地机器通过邮递员触发它并使用参数,名称:示例时,我得到下面的正确响应,

{"size":"0","total":1182,"from":"0"}

但是当我部署它并使用相同的参数在邮递员上测试时,我收到状态 500 内部服务器错误。 当我在 azure 门户上尝试时,我得到 200 OK,但输出如下,

<html style="height:100%"><head><Meta NAME="ROBOTS" CONTENT="NOINDEX,nofollow"><Meta             
name="format-detection" content="telephone=no"><Meta name="viewport" content="initial-    scale=1.0">    <Meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><script     type="text/javascript" src="/_Incapsula_Resource?SWJIYLWA=719d34d31c8e3a6e6fffd425f7e032f3">    </script></head><body style="margin:0px;height:100%"><iframe id="main-iframe"     src="/_Incapsula_Resource?CWUDNSAI=23&xinfo=3-66669102-    0%200NNN%20RT%281627064616349%205%29%20q%280%20-1%20-1%200%29%20r%280%20-    1%29%20B16%20U5&incident_id=374000410210161318-    229498008368450115&edet=16&cinfo=ffffffff&rpinfo=0&mth=GET" frameborder=0 width="100%"     height="100%" marginheight="0px" marginwidth="0px">Request unsuccessful. Incapsula incident ID:     374000410210161318-229498008368450115</iframe></body></html>

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