azure - HTTP 502:当一个函数与另一个计划函数保持温暖时
问题描述
我有一个 HTTP 触发的消费计划 Azure 函数,我想通过定期向它发布一个空的有效负载来保持温暖。
我正在使用具有此配置的计划函数执行此操作:
__init__.py
import os
import datetime
import logging
import azure.functions as func
import urllib.parse, urllib.request, urllib.error
def main(mytimer: func.TimerRequest) -> None:
try:
url = f"https://FUNCTIONNAME.azurewebsites.net/api/predictor?code={os.environ['CODE']}"
request = urllib.request.Request(url, {})
response = urllib.request.urlopen(request)
except urllib.error.HTTPError as e:
message = e.read().decode()
if message == "expected outcome":
pass
else:
logging.info(f"Error: {message}")
函数.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */9 5-17 * * 1-5"
}
]
}
当我检查我的日志时,它们充满了 HTML。这是 HTML 的一个片段:
...
<h1>Server Error</h1>
...
<h2>502 - Web server received an invalid response while acting as a gateway or proxy server.</h2>
<h3>There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.</h3>
在本地运行__init__.py的逻辑可以正常工作。这里可能有什么问题?
解决方案
嗯……这很奇怪。看起来响应无法路由到我猜的正确实例。
顺便说一句,我相信您可以在与您想要保暖的功能应用程序相同的功能应用程序中简单地使用时间触发功能。这个函数真的不需要做任何事情。
此外,您可能想查看支持预热实例的Azure Functions Premium 。请注意,这仍处于预览阶段。
推荐阅读
- python - executemany - 错误消息 错误绑定参数 0 - 可能不受支持的类型
- java - 在 IntelliJ IDEA 中取消注释 javadoc 的快捷方式
- ruby-on-rails - 如何使用 rails gem 在 shopify API 产品上添加分页
- java - 任何人都应该在实时开发环境中使用单元测试库方法和类吗?
- android - 无法使用多个光标从 SQLite 检索数据
- image-processing - 什么是图像的自然度
- typescript - TypeScript (v3.1.3):给通用类型接口起别名?
- python-3.x - 如何在 django 2 中的 html 内容中传递值
- javascript - 如何在spring mvc中将数组变量从视图传递到控制器
- java - Android Studio Auto 生成的公共最终类 R 文件