简体   繁体   English

ECONNRESET 从 flask python 获取错误响应

[英]ECONNRESET Error response getting from flask python

I'm not getting the proper response for this particular API.对于这个特定的 API,我没有得到正确的响应。 Also, In actual implementation, I'm getting the proper 200 jsonify response when all things are running fine but if their is any exception and If I want to send back the response with 500 status code: the postman say Could not get response: "Error: read ECONNRESET" and in my console it display as "127.0.0.1 - - [04/Aug/2020 23:57:22] "←[37mPOST /hi HTTP/1.1←[0m" 500 -"此外,在实际实施中,当所有事情都运行良好时,我会得到正确的 200 jsonify 响应,但如果它们有任何异常,并且如果我想用 500 状态代码发回响应:postman 说无法得到响应:“错误:读取 ECONNRESET”并在我的控制台中显示为“127.0.0.1 - - [04/Aug/2020 23:57:22]”←[37mPOST /hi HTTP/1.1←[0m”500 -”

can someone please tell me, where I'm going wrong?有人可以告诉我,我要去哪里错了吗?

from flask import Flask, jsonify, request, abort, json
from werkzeug.utils import secure_filename
from werkzeug.exceptions import HTTPException
from flask_cors import CORS, cross_origin
import traceback

app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'

@app.route("/hi", methods=['POST'])
def hi():
    val = 500
    dict_json = {"messgae": "lets work it out {} ".format(val)}
    return jsonify(dict_json), val

I had this problem today and found that it seems to be an issue with the flask server.今天遇到这个问题,发现好像是flask服务器的问题。 It works fine usually however sometimes requests with postman would time out with the error you've mentioned.它通常工作正常,但有时使用 postman 的请求会因您提到的错误而超时。

Can you try hosting it instead with waitress?你可以尝试用女服务员来代替它吗?

To do that add this to the top of your file为此,请将其添加到文件的顶部

from waitress import serve从女服务员进口服务

then instead of running app.run() you run serve(app, host='localhost', port=7777)然后你运行serve(app, host='localhost', port=7777)而不是运行app.run( )

oh, and for waitress to work you will of course need to run pip install waitress first!哦,为了让服务员工作,你当然需要先运行pip 安装服务员

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM