Skip to content
Myr

Add an example of two hooks

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alex Chan · committed by Alex Chan · parent 40c5a8b · Browse files · 1 file+12 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+12 added−0 removed

  • other:+12 added−0 removed

1 file+12 added−0 removed

modified:docs/user/advanced.rst+12 added
450 unmodified lines
451If the callback function returns a value, it is assumed that it is to452replace the data that was passed in. If the function doesn't return453anything, nothing else is effected.454455::456457 def record_hook(r, *args, **kwargs):458 r.hook_called = True459 return r460461Let's print some request method arguments at runtime::462463 >>> requests.get('http://httpbin.org', hooks={'response': print_url})464 http://httpbin.org465 <Response [200]>466467You can add multiple hooks to a single request. Let's call two hooks at once::468469 >>> r = requests.get('http://httpbin.org', hooks={'response': [print_url, record_hook]})470 >>> r.hook_called471 True472473You can also add hooks to a ``Session`` instance. Any hooks you add will then474be called on every request made to the session. For example::475476 >>> s = requests.Session()
560 unmodified lines