python-requests - Python请求无法识别来自服务器对高延迟请求的响应
问题描述
我正在尝试测试请求模块以触发需要很长时间才能运行的云中的服务(例如 Google Cloud Functions/Cloud run)。
我创建了一个测试服务,它在 45 分钟后提供一个 Json 响应对象。我可以在云运行日志中看到它工作正常并以 200 状态结束。
@app.route("/")
def test_high_latency_request():
i=0
while i < 9:
time.sleep(300)
i+=1
print(str(i*5) + " mins have passed")
response_json = {
"asgfd":"dagdfs",
"fgasdg":"gsadgs"
}
return response_json, 200
if __name__=="__main__":
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
但是,即使响应可用,以下任何一个请求都不会收到响应,函数会无限期地继续运行,或者直到达到指定的超时时间,即使响应可用,从 Cloud Run 日志中可以看出。
requests.get("https://high-latency-conn-test-hyk3kw2bxq-nw.a.run.app",stream=True)
requests.get("https://high-latency-conn-test-hyk3kw2bxq-nw.a.run.app",timeout=(3600,3600))
我也尝试过启动 requests.Session() 实例,但这也无济于事。
如何使用此模块处理高延迟请求?或者我应该使用不同的库。
解决方案
推荐阅读
- flutter - Flutter JWT 访问/刷新
- delphi - Delphi 10.4.2 - 如何修复“元素中缺少必需的属性“包含”
“ 错误? - sql - 在 SQL 中连接日期和时间以获取 datetime: 1900-01-01 而不是实际日期错误
- python - 具有奇怪行为的 Keras 模型预测:“training=True”时高acc,否则不好
- amazon-web-services - aws quicksight - 未能满足约束:在此区域中无法访问指定的资源('us-east-1')
- html - What's the use of Content-Type header when the response is an attachment?
- django - 在我的仪表板的views.py 中写什么?
- linux - 在 Linux 中查找并复制包含模式的多个文件
- linux - 如何在 bash 脚本中获取分区标签
- html - 我的 CSS 代码在 Chrome 中不起作用,内联 CSS、内部 CSS 或外部 CSS 都不起作用