在IIS 7.5上部署应用程序时,Flask POST请求会挂起

时间:2015-10-05 00:37:02

标签: python django iis flask django-rest-framework

我使用了Miguel Grinberg的blog的小烧瓶测试应用程序,并尝试将其部署在IIS上。它在我的POST请求正在工作的本地系统上正常运行。

但是当我将其部署到IIS 7.5(Windows Server 2008 R2 Datacenter版本)时会出现问题。

我使用此post配置IIS。

然后当我向服务器发出POST请求时,我没有得到回复。

我的代码:

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)

使用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

在IIS服务器上测试:

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

它挂在那里。经过一段时间(15分钟)后,我得到了一个很长的HTML响应,说明了超时。

1 个答案:

答案 0 :(得分:0)

也许你错过了一个WSGI参考?

尝试在代码末尾进行以下修改

wsgi_app = app.wsgi_app

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