-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support passing in a Session
object
#13
Comments
Hey - is this something you need yourself? I ask as I'd be surprised if this were a common use-case. I imagine 99.9% of calls using requests are directly to the I really appreciate the interest and the offer to implement it, but I'd rather try to keep the API as thin and uncomplicated as possible. (Indeed, in the next version, I'll have deprecated the So, I'll close this for the time being, and if there's more interest, I'll consider reopening it and implementing it. |
Yes, this is something we use ourselves. Direct copy and paste from our codebase: # TODO: simplify to this one-liner once https://github.com/kopf/httsleep/issues/13 is addressed
# httsleep(url, session=self._session, until=until, alarms=alarms, max_retries=15, polling_interval=4)
poller = HttSleeper(url, until=until, alarms=alarms, max_retries=15, polling_interval=4,
headers=self._session.headers)
poller.session = self._session
poller.run() I can understand wanting to keep the API simple, but at very least I'd love to change (As it happens, passing in the session obviates our use case for issue #11, since you can define |
Just trying to understand your problem more deeply -
is there anything stopping you from making use of the `headers` kwarg that
httsleep already provides? Or, to put it differently: once #12 is merged
and you can tell httsleep to skip SSL cert verification, is there anything
you'd gain by being able to do `session=mysession` instead of
`headers=myheaders` (or `headers=mysession.headers`)?
|
That's a fair question. The fact is that we're making a number of HTTP calls to various endpoints on the same service, as follows:
Since we need to pass an auth token header and session = requests.Session()
session.verify = False
session.headers.update({'Authorization': 'token=%s' % my_token}) and then pass that an everywhere, rather than put the auth header (along with any endpoint-specific headers!) and |
OK, you've convinced me! :) The API you've proposed (extra It should be made clear to the end user what happens when they do something like:
|
Glad to hear it! I'll wait until the outstanding PR #12 has been merged before working on this, to avoid clashes. |
Users may already have a
requests.Session
object and wish to reuse that rather than havinghttsleep
create a blank one. This would save users from re-entering standard headers, settings etc. that they've already configured elsewhere.Ideal usage afterwards:
~~~Workaround~~~ Not usable
Not usable because here the request is prepared without the context of the Session:
The workaround would be usable if this line was instead:
The text was updated successfully, but these errors were encountered: