【发布时间】:2012-12-18 23:57:18
【问题描述】:
我需要猴子补丁请求的响应类(版本 1.0.4,截至本问题的当前版本),以添加其他方法。
我有这个代码:
import requests
class Response(requests.models.Response):
def hmm(self):
return 'ok'
requests.models.Response = Response
r = requests.get('http://bbc.co.uk')
print r
当原始响应调用 super() 时失败 - https://github.com/kennethreitz/requests/blob/master/requests/models.py#L391
我认为这是因为它变得混乱,因为我已经更换了班级,我觉得我在做一些愚蠢的事情,有什么想法吗?提前致谢。
【问题讨论】:
-
In [2]: requests.__version__ Out[2]: '1.0.4' 你也是这样吗?此代码曾经适用于旧版本的请求
-
文件 "/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/models.py",第 391 行,在 init 中 super(Response, self).__init__() TypeError: super(type, obj): obj must be an instance or subtype of type
标签: python monkeypatching