我在使用 python 请求模块对我的应用程序进行文档测试时遇到了一些问题,直到现在才能够得到它。有时会发生缺少响应主体的情况。但是当我用 ngrep 查看网络请求/响应时,我可以看到响应正文。所以它似乎被python模块忽略了。这使我的文档测试非常不稳定,因此毫无用处。
>>> response = requests.get('/api/v1/profile/%s/affiliations' % urllib.quote(profileId1))
>>> affiliations = response.json
>>> pprint(affiliations)
[{u'name': u'Affiliation A'},
{u'name': u'Affiliation B'}]
Failed example:
pprint(affiliations)
Differences (ndiff with -expected +actual):
+ None
- [{u'name': u'Affiliation A'},
- {u'name': u'Affiliation B'}]
ngrep 跟踪如下所示:
###########
T 127.0.0.1:62252 -> 127.0.0.1:9000 [AP]
GET /api/v1/profile/4fde28e80364cb830f649ee1/affiliations HTTP/1.1.
Host: localhost:9000.
Connection: close.
Accept-Encoding: identity, deflate, compress, gzip.
Accept: application/json.
User-Agent: python-requests/0.13.0.
.
##
T 127.0.0.1:9000 -> 127.0.0.1:62252 [AP]
HTTP/1.1 200 OK.
Content-Type: application/json; charset=utf-8.
Content-Length: 63.
.
[{"name":"Affiliation A"},{"name":"Affiliation B"}]
###########