简体   繁体   中英

ECONNRESET Error response getting from flask python

I'm not getting the proper response for this particular 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 -"

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. It works fine usually however sometimes requests with postman would time out with the error you've mentioned.

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)

oh, and for waitress to work you will of course need to run pip install waitress first!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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