python请求模块不加载响应内容

时间:2012-06-17 19:12:26

标签: python module python-requests

我在使用python请求模块对我的应用程序进行doctest时遇到了一些问题,直到现在才能得到它。 有时会发生缺少响应主体的情况。但是当我用ngrep查看网络请求/响应时,我可以看到响应正文。所以它似乎被python模块忽略了。这使我的doctests非常不稳定,从而无用。

>>> 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"}]
###########

0 个答案:

没有答案