我把空闲超时设置为60分钟。但是,在使用Python客户机与Python服务器对话的情况下,当发送POST时,连接通过对等方重置约5分钟的不活动时间。即使在连接被重置或断开之后,该活动仍在服务器端发生。
import requests
import logging
import flask
from flask import Flask
app = Flask(__name__)
logging.basicConfig(level=logging.INFO, format=f'%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
@app.before_first_request
def before_first_request():
app.logger.info("before_first_request")
@app.before_request
def before_request():
app.logger.info("before_request")
@app.route('/run', methods=['POST'])
def run(redirect_url="",additional_testng_parameters=""):
url = "http://192.168.1.8:7070/" + "run"
app.logger.info("url is:" + url)
session = requests.Session()
app.logger.info("Request placed for " + url)
response = "Text"
try:
response = session.post(url=url, timeout=3600)
resultdata = response.headers['Content-Type']
app.logger.info("Response received for : " + url + " is:" + str(response.status_code))
app.logger.info("Response received for : " + url + " is:" + str(resultdata))
response = make_response("Execution is successful")
except Exception as err:
app.logger.error(err)
return response
@app.errorhandler(Exception)
def server_error(err):
app.logger.exception(err)
return "There is some error on Test Invoker side", 500
if __name__ == '__main__':
from waitress import serve
serve(app, host="0.0.0.0", port=8080)
大约在5分钟后得到以下错误消息
ERROR app waitress-0 : ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
以下是一些参考资料,但并不能解决我的问题。
https://www.pythonfixing.com/2022/01/fixed-aborted-remotedisconnected-end.html
下面的代码帮助我解决了这个问题
import socket
from urllib3.connection import HTTPConnection
HTTPConnection.default_socket_options = (
HTTPConnection.default_socket_options + [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
(socket.SOL_TCP, socket.TCP_KEEPIDLE, 45),
(socket.SOL_TCP, socket.TCP_KEEPINTVL, 10),
(socket.SOL_TCP, socket.TCP_KEEPCNT, 6)
]
)
发布于 2022-06-07 08:02:53
试试这个:
import socket
from urllib3.connection import HTTPConnection
HTTPConnection.default_socket_options = (
HTTPConnection.default_socket_options + [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
(socket.SOL_TCP, socket.TCP_KEEPIDLE, 45),
(socket.SOL_TCP, socket.TCP_KEEPINTVL, 10),
(socket.SOL_TCP, socket.TCP_KEEPCNT, 6)
]
)
https://stackoverflow.com/questions/72393655
复制相似问题