Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 同一项目中另一个调用的Azure函数没有响应(冻结)_Python 3.x_Http_Python Requests_Azure Functions - Fatal编程技术网

Python 3.x 同一项目中另一个调用的Azure函数没有响应(冻结)

Python 3.x 同一项目中另一个调用的Azure函数没有响应(冻结),python-3.x,http,python-requests,azure-functions,Python 3.x,Http,Python Requests,Azure Functions,我在VS代码中的同一个项目中有两个Azure函数。它们是用Python 3.8编写的。它们都是通过GET或POST请求触发的HTTP。它们是使用针对VS代码的Azure函数扩展制作的 他们的授权级别都设置为匿名,这意味着他们应该接受来自任何地方的请求 它们具有相同的HttpTrigger[1,2]/function.json文件: { “脚本文件”:“\uuuu init\uuuuu.py”, “绑定”:[ { “authLevel”:“匿名”, “类型”:“httpTrigger”, “方向”

我在VS代码中的同一个项目中有两个Azure函数。它们是用Python 3.8编写的。它们都是通过GET或POST请求触发的HTTP。它们是使用针对VS代码的Azure函数扩展制作的

他们的授权级别都设置为匿名,这意味着他们应该接受来自任何地方的请求

它们具有相同的
HttpTrigger[1,2]/function.json
文件:

{
“脚本文件”:“\uuuu init\uuuuu.py”,
“绑定”:[
{
“authLevel”:“匿名”,
“类型”:“httpTrigger”,
“方向”:“在”,
“名称”:“请求”,
“方法”:[
“得到”,
“职位”
]
},
{
“类型”:“http”,
“方向”:“输出”,
“名称”:“$return”
}
]
}
我正在尝试使用
HttpTrigger1
使用
requests
库向
HttpTrigger2
发出GET请求

HttpTrigger1/\uuuu init\uuuu.py

导入日志
导入请求
将azure.1函数导入为func
def main(请求:func.HttpRequest)->func.HttpResponse:
info(“Python HTTP触发器函数处理了一个请求。”)
请求。获取(“http://localhost:7071/api/HttpTrigger2")
返回func.HttpResponse(
“HttpTrigger1已成功执行。”,
状态代码=200,
)
HttpTrigger2/\uuuu init\uuuu.py

导入日志
将azure.1函数导入为func
def main(请求:func.HttpRequest)->func.HttpResponse:
info(“Python HTTP触发器函数处理了一个请求。”)
返回func.HttpResponse(
“HttpTrigger2已成功执行。”,
状态代码=200,
)
日志文件输出:

> Executing task: .venv/bin/python -m pip install -r requirements.txt <

Requirement already satisfied: azure-functions in ./.venv/lib/python3.8/site-packages (from -r requirements.txt (line 5)) (1.6.0)
source /home/jim/azureTest/.venv/bin/activCollecting requests
ate
  Using cached requests-2.25.1-py2.py3-none-any.whl (61 kB)
Collecting idna<3,>=2.5
  Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting chardet<5,>=3.0.2
  Using cached chardet-4.0.0-py2.py3-none-any.whl (178 kB)
Collecting urllib3<1.27,>=1.21.1
  Using cached urllib3-1.26.3-py2.py3-none-any.whl (137 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
Installing collected packages: idna, chardet, urllib3, certifi, requests
Successfully installed certifi-2020.12.5 chardet-4.0.0 idna-2.10 requests-2.25.1 urllib3-1.26.3

Terminal will be reused by tasks, press any key to close it.

> Executing task: . .venv/bin/activate && func host start <

Found Python version 3.8.5 (python3).

Azure Functions Core Tools
Core Tools Version:       3.0.3388 Commit hash: fb42a4e0b7fdc85fbd0bcfc8d743ff7d509122ae 
Function Runtime Version: 3.0.15371.0


Functions:

        HttpTrigger1: [GET,POST] http://localhost:7071/api/HttpTrigger1

        HttpTrigger2: [GET,POST] http://localhost:7071/api/HttpTrigger2

For detailed output, run func with --verbose flag.
[2021-03-15T06:15:36.426Z] Worker process started and initialized.
[2021-03-15T06:15:40.953Z] Host lock lease acquired by instance ID '000000000000000000000000861DE9B7'.
[2021-03-15T06:15:45.946Z] Executing 'Functions.HttpTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=a82a749d-4e0d-40e4-b9ff-358c8e38a24e)
[2021-03-15T06:15:46.039Z] Python HTTP trigger function processed a request.
[2021-03-15T06:15:46.046Z] Executing 'Functions.HttpTrigger2' (Reason='This function was programmatically called via the host APIs.', Id=c3291b34-ee0d-4b5d-8b67-1a1bcb4474f6)
>正在执行任务:.venv/bin/python-m pip install-r requirements.txt<
已满足要求:azure函数位于./.venv/lib/python3.8/site-packages中(来自-r requirements.txt(第5行))(1.6.0)
source/home/jim/azureTest/.venv/bin/activCollecting请求
吃了
使用缓存的请求-2.25.1-py2.py3-none-any.whl(61 kB)
收集idna=2.5
使用缓存的idna-2.10-py2.py3-none-any.whl(58 kB)
收集字符数=3.0.2
使用缓存的chardet-4.0.0-py2.py3-none-any.whl(178KB)
正在收集urllib3=1.21.1
使用缓存的urllib3-1.26.3-py2.py3-none-any.whl(137 kB)
收款凭证i>=2017.4.17
使用缓存的certifi-2020.12.5-py2.py3-none-any.whl(147 kB)
安装收集的包:idna、chardet、urllib3、certifi、requests
已成功安装certifi-2020.12.5 chardet-4.0.0 idna-2.10请求-2.25.1 urllib3-1.26.3
终端将被任务重用,请按任意键将其关闭。
>正在执行的任务:。venv/bin/activate&&func主机启动<
找到了Python版本3.8.5(python3)。
Azure功能核心工具
核心工具版本:3.0.3388提交哈希:fb42a4e0b7fdc85fbd0bcfc8d743ff7d509122ae
函数运行时版本:3.0.15371.0
功能:
HttpTrigger1:[获取,发布]http://localhost:7071/api/HttpTrigger1
HttpTrigger2:[获取,发布]http://localhost:7071/api/HttpTrigger2
对于详细输出,请使用--verbose标志运行func。
[2021-03-15T06:15:36.426Z]工作进程已启动并初始化。
[2021-03-15T06:15:40.953Z]主机锁租约已由实例ID“000000000000000000000000861DE9B7”获取。
[2021-03-15T06:15:45.946Z]正在执行“Functions.HttpTrigger1”(原因=“此函数是通过主机API以编程方式调用的”,Id=a82a749d-4e0d-40e4-b9ff-358c8e38a24e)
[2021-03-15T06:15:46.039Z]Python HTTP触发器函数处理了一个请求。
[2021-03-15T06:15:46.046Z]执行“Functions.HttpTrigger2”(原因=“此函数是通过主机API编程调用的”,Id=c3291b34-ee0d-4b5d-8b67-1a1bcb4474f6)
然而,执行永远不会进步
HttpTrigger2
从不记录任何内容,控件也不会返回到
HttpTrigger1
。我应该如何从一个Azure函数向另一个Azure函数发出HTTP请求?日志中没有显示任何错误,并且在未通过
HttpTrigger1
的情况下调用
HttpTrigger2
,工作正常。无论我是否进入浏览器并键入
http://localhost:7071/api/HttpTrigger1
,向邮递员发出请求或使用Azure功能扩展“立即执行功能”


一个主机实例一次只能提供一个功能。正如Bowman所说,如果使用async,那么就可以解决这个问题

如果出于某种原因您不想使用异步,那么其他选项:

  • (未测试)在主机中使用。不确定本地环境是否支持此操作。请注意,这将导致每个进程共享该主机的资源
  • 部署到云端并进行测试。它应该扩展工作进程并生成一个新实例来承载第二个函数

我接受了不同的回答作为最佳答案,但为了完整起见,我还想在这里发布我自己的解决方案,使用
http3

HttpTrigger1/\uuuu init\uuuu.py

导入日志
进口http3
将azure.1函数导入为func
异步def main(请求:func.HttpRequest)->func.HttpResponse:
info(“Python HTTP触发器函数处理了一个请求。”)
client=http3.AsyncClient()
等待客户。获取(“http://localhost:7071/api/HttpTrigger2")
返回func.HttpResponse(
“HttpTrigger1已成功执行。”,
状态代码=200,
)
HttpTrigger2/\uuuu init\uuuu.py

导入日志
将azure.1函数导入为func
def main(请求:func.HttpRequest)->func.HttpResponse:
info(“Python HTTP触发器函数处理了一个请求。”)
返回func.HttpResponse(
“HttpTrigger2已成功执行。”,
状态代码=200,
)

与本文类似:您链接到的PyPI页面显示要使用
导入http3;client=http3.AsyncClient();等待客户端。获取(…)
。这是可行的,但你能解释一下原因吗?@jamesh625请检查你的日志输出。您的两个函数是syn
import logging

import azure.functions as func
import requests_async as requests

async def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    response = await requests.get('http://localhost:7071/api/HttpTrigger2')
    return func.HttpResponse(
            "Test"+response.text,
            status_code=200
    )