使用Requests Python包的钩子问题

Problems with hooks using Requests Python package

我正在使用模块requests,当我开始使用钩子时,我收到了这条消息。

1
2
3
4
5
6
7
8
9
File"/Library/Python/2.7/site-packages/requests-1.1.0-py2.7.egg/requests/sessions.py", line 321, in request
resp = self.send(prep, **send_kwargs)

File"/Library/Python/2.7/site-packages/requests-1.1.0-py2.7.egg/requests/sessions.py", line 426, in send
r = dispatch_hook('response', hooks, r, **kwargs)

File"/Library/Python/2.7/site-packages/requests-1.1.0-py2.7.egg/requests/hooks.py", line 41, in dispatch_hook
_hook_data = hook(hook_data, **kwargs)
TypeError: hook() got an unexpected keyword argument 'verify'

这是我的代码(简化):

1
2
3
4
5
import requests
def hook(r):
     print r.json()

r = requests.get("http://search.twitter.com/search.json?q=blue%20angels&rpp=5", hooks=dict(response=hook))


根据请求文档,你的钩子函数不需要接受任何关键字参数,但是根据github上的源代码,事件调度程序可以将kwargs传递给你的钩子函数。 对我来说似乎不完整的文档。 将您的方法重新定义为:

1
2
def hook(r, **kwargs):
    # ...