6

I'm using the module requests and I recieved this message when I started using hooks.

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'

And this is my code (simplified):

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))
masipcat
  • 109
  • 3
  • 12
  • I think you need to check what the server is sending you. – elssar Mar 24 '13 at 01:10
  • The same code without hooks work fine: `import requests` `r = requests.get("http://search.twitter.com/search.json?q=blue%20angels&rpp=5")` `print r.json()` – masipcat Mar 24 '13 at 01:17

1 Answers1

21

According to the requests documentation, your hook function doesnt need to take any keyword arguments, but according to the source code on github, the event dispatcher may pass on kwargs to your hook function. Seems like incomplete documentation to me. Redefine your method as:

def hook(r, **kwargs):
    # ...
Josh Bothun
  • 1,324
  • 9
  • 9