简体   繁体   中英

Flask POST requests hang when application deployed on IIS 7.5

I used a small flask test application from Miguel Grinberg's blog and tried to deploy it on IIS. It works run fine on my local system where POST requests are working.

But a problem occurs when I deploy it to IIS 7.5 (Windows Server 2008 R2 Datacenter edition).

I used this post to configure IIS.

Then when I perform a POST request to the server I don't get a response back.

My code:

from flask import Flask, jsonify
from flask import abort
from flask import make_response,request


app = Flask(__name__)


@app.errorhandler(404)
def not_found(error):
    return make_response(jsonify({'error': 'Not found'}), 404)

@app.route('/dsebws', methods=['POST'])
def create_task():    
    d=request.data
    tp= str(type(d))
    return jsonify({'task': tp}), 201

if __name__ == '__main__':
    app.run(debug=Tr

ue)

Test result local using python app.py :

C:\Users\xyz>curl -v -X POST -d "Test" http://localhost:5000/dsebws
* About to connect() to localhost port 5000 (#0)
*   Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 5000 (#0)
> POST /dsebws HTTP/1.1
> User-Agent: curl/7.28.1
> Host: localhost:5000
> Accept: */*
> Content-Length: 4
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 4 out of 4 bytes
* HTTP 1.0, assume close after body
< HTTP/1.0 201 CREATED
< Content-Type: application/json
< Content-Length: 28
< Server: Werkzeug/0.10.4 Python/2.7.9
< Date: Mon, 05 Oct 2015 00:30:54 GMT
<
{
  "task": "<type 'str'>"
}* Closing connection #0

Tested on IIS Server:

PS C:\Users\tarik> curl -v -X POST -d "tarik" http://localhost:80/dsebws
* About to connect() to localhost port 80 (#0)
*   Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> POST /dsebws HTTP/1.1
> User-Agent: curl/7.28.1
> Host: localhost
> Accept: */*
> Content-Length: 5
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 5 out of 5 bytes

And it hangs there. After some time (15 mins) I get a long HTML response says something about a timeout.

Perhaps you're missing a WSGI reference?

Try putting in the following modifications at the end of your code

wsgi_app = app.wsgi_app

if __name__ == '__main__':
    app.run(debug=True)

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