1

我正在为烧瓶应用程序编写一些测试用例。

这个应用程序有一个这样的蓝图:

@api_blueprint.route('/api/search/', methods=['GET'])
def search():
   ...

我的测试试图验证这样的请求:

http://127.0.0.1:5000/api/search

返回状态码 301

该测试在 CentOS 6 服务器上运行良好(以及在我尝试过的任何其他 linux 机器上)

事实上,一个非常简单的 get 请求会给出正确的结果:

In [1]: import requests
In [2]: r = requests.get('http://127.0.0.1:5000/api/search')
Starting new HTTP connection (1): 127.0.0.1
In [3]: r.history
Out[3]: (<Response [301]>,)

但它在我的 Mac Pro 上失败了,通过 MacPorts 安装了 Mac OS X 10.6.8 和 python 2.6。

在 Mac 上,同样的简单请求直接给出状态码 200:

In [1]: import requests
In [2]: r = requests.get('http://127.0.0.1:5000/api/search')
Starting new HTTP connection (1): 127.0.0.1
In [3]: r.history
Out[3]: []
In [4]: r.status_code
Out[4]: 200

显然我已经检查过我在两台机器上都有相同版本的 Flask。

有人知道为什么会有这种令人讨厌的行为差异吗?

谢谢!

4

0 回答 0