Comments (3)
Like most other functionality requests_futures
hooks are straight pass throughs of the underlying requests
library https://docs.python-requests.org/en/latest/user/advanced/#event-hooks
Probably the easiest way to tie data to a specific request is to use an inline function:
#!/usr/bin/env python
from pprint import pprint
import requests
def get(url, params, hook_arg):
def hook(response, *args, **kwargs):
pprint({
'hook_arg': hook_arg,
'request': response.request,
'response': response,
'json': response.json(),
'args': args,
'kwargs': kwargs,
})
requests.get(url, params=params, hooks={'response': [hook]})
get('https://nghttp2.org/httpbin/get', {'call': 'first'}, 42)
get('https://nghttp2.org/httpbin/get', {'call': 'second'}, 43)
$ ./args.py
{'args': (),
'hook_arg': 42,
'json': {'args': {'call': 'first'},
'headers': {'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Host': 'nghttp2.org',
'User-Agent': 'python-requests/2.26.0'},
'origin': 'xx.xx.xx.xx',
'url': 'https://nghttp2.org/httpbin/get?call=first'},
'kwargs': {'cert': None,
'proxies': OrderedDict(),
'stream': False,
'timeout': None,
'verify': True},
'request': <PreparedRequest [GET]>,
'response': <Response [200]>}
{'args': (),
'hook_arg': 43,
'json': {'args': {'call': 'second'},
'headers': {'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Host': 'nghttp2.org',
'User-Agent': 'python-requests/2.26.0'},
'origin': 'xx.xx.xx.xx',
'url': 'https://nghttp2.org/httpbin/get?call=second'},
'kwargs': {'cert': None,
'proxies': OrderedDict(),
'stream': False,
'timeout': None,
'verify': True},
'request': <PreparedRequest [GET]>,
'response': <Response [200]>}
You also have full access to the request object so anything associated with it will be accessible.
from requests-futures.
Okay thank you. I used a closure. Not sure what's the use of params=params
here. I thought that this is how I could pass parameters.
from requests-futures.
Not sure what's the use of
params=params
here.
It was just to pass different params into the get
so that they'd show up in the httpbin output.
from requests-futures.
Related Issues (20)
- OSError Issues when used within celery task (gevent) HOT 2
- Adding attribute to response via hook (as seen in examples) fails HOT 1
- Cannot switch to a different thread HOT 3
- Possibility to accept old SSL versions? HOT 1
- Problem with data field in header request HOT 1
- Making a future request and letting callback work with result - some are missing HOT 2
- Error When there is a large parallel Requests go. HOT 2
- Provide wheels on PyPI HOT 1
- AttributeError: 'Future' object has no attribute 'status_code' HOT 1
- 1.0.0: missing git tag HOT 5
- Response for batched requests HOT 6
- Add type annotations HOT 4
- Not showing as updated on PyPI HOT 3
- On exception it returns xx (Caused By None), whereas the requests module returns xx (Caused By xx) HOT 4
- The elapsed time hook example does not work HOT 3
- 1.0.0: pytest is failing in two units HOT 6
- Use pytest-httpbin? HOT 8
- Attribute set via response hooks does not work with ProcessPoolExecutor HOT 4
- RFE: preserve contextvars when performing the request HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from requests-futures.