【发布时间】:2016-11-01 13:43:33
【问题描述】:
出于测试目的,我尝试在 python 中创建一个 Response() 对象,但事实证明它比听起来更难。
我试过这个:
from requests.models import Response
the_response = Response()
the_response.code = "expired"
the_response.error_type = "expired"
the_response.status_code = 400
但是当我尝试the_response.json() 时出现错误,因为该函数试图获取len(self.content) 而a.content 为空。
所以我设置了a._content = "{}",然后我得到一个编码错误,所以我必须更改a.encoding,但是它无法解码内容......
这种情况一直在继续。有没有一种简单的方法来创建一个具有功能且具有任意 status_code 和内容的 Response 对象?
【问题讨论】: