【问题标题】:Remote end closed connection without response in apache airflow jobApache 气流作业中没有响应的远程关闭连接
【发布时间】:2022-08-16 08:45:44
【问题描述】:
我在 apache 气流作业中执行 python 服务调用,POST 调用是直截了当的,但 5 分钟后,它失败并出现此错误“远程结束关闭连接没有响应”。
res = requests.post(url, verify=False, auth=token) //The server responds in 5 to 10 minutes after it process few items
注意:使用 \"CURL\" 命令可以正常调用相同的调用。持续 8 分钟后收到回复
我想了解谁在关闭连接?是客户端、服务器端还是 Apache 气流?由于 CURL 命令工作正常,服务器端似乎没问题。我是否需要更改客户端 python 请求调用超时等或 Apache 气流端更改?
标签:
python-3.x
python-requests
airflow
【解决方案1】:
我使用 TCPKeepAliveAdapter 使它工作。这是现在的代码,
import requests
from requests_toolbelt.adapters.socket_options import TCPKeepAliveAdapter
session = requests.Session()
keep_alive = TCPKeepAliveAdapter(idle=120, count=120, interval=60)//We are telling server that am alive.After 2 minutes it starts pinging server 120 times with 1 minute interval.
session.mount("https://", keep_alive)
res = session.post(url, verify=False, auth=token))