【问题标题】:Flask POST requests hang when application deployed on IIS 7.5当应用程序部署在 IIS 7.5 上时,Flask POST 请求挂起
【发布时间】:2015-10-05 00:37:02
【问题描述】:

我使用了来自 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

u)

本地使用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 响应,说明超时。

【问题讨论】:

  • 请在您的帖子中添加“某事”。
  • 尝试发送内容长度为 388 的 json ......但仍然......同样的问题,没有回复

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


【解决方案1】:

也许您缺少 WSGI 参考?

尝试在代码末尾添加以下修改

wsgi_app = app.wsgi_app

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 2013-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多