Skip to content
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

Requests arguments #105

Open
mngmntt opened this issue Feb 5, 2015 · 4 comments
Open

Requests arguments #105

mngmntt opened this issue Feb 5, 2015 · 4 comments

Comments

@mngmntt
Copy link
Contributor

mngmntt commented Feb 5, 2015

Hi Sam,

what do you think about passing requests parameters through slumber such as timeout, proxies, stream, etc. At this moment the only way is to overwrite slumber's _request method.

I will create PR if you support this decision.

Cheers,
Alex

@samgiles
Copy link
Owner

Good idea. I shall do this!

Thanks for the suggestion

@jhermann
Copy link
Contributor

For most / all things you mentioned, you can also pass in your own session, especially if they're not really per-request (like timeouts which most often are fixed per application / API use).

@IAlwaysBeCoding
Copy link

@jhermann I think it should be a simple fix of adding kwargs to the API class to set values such as timeouts,stream,proxy,even user-agent to the requests.Session instance stored in self._store .

IAlwaysBeCoding added a commit to IAlwaysBeCoding/More that referenced this issue Aug 23, 2015
Added the ability to pass session wide parameters to the requests.Session object.
IAlwaysBeCoding added a commit to IAlwaysBeCoding/More that referenced this issue Aug 25, 2015
Closing samgiles#105 and using this as a replacement PR. I think it would be better to document these options instead of changing the API object.
IAlwaysBeCoding added a commit to IAlwaysBeCoding/More that referenced this issue Aug 25, 2015
Added the ability to pass session wide parameters to the requests.Session object.
@daisylb
Copy link

daisylb commented May 27, 2016

FWIW, timeouts can't actually be set in a Session; I think they used to be in earlier versions of Requests but not anymore, and they won't be added (see kennethreitz/requests#2011). So, currently, adding a default timeout looks like this:

class TimeoutHTTPAdapter(HTTPAdapter):
    def __init__(self, timeout=None, *args, **kwargs):
        self.timeout = timeout
        super().__init__(*args, **kwargs)

    def send(self, *args, **kwargs):
        kwargs['timeout'] = self.timeout
        return super().send(*args, **kwargs)

_session = Session()
_session.mount("http://", TimeoutHTTPAdapter(timeout=3))

Which is quite a lot of boilerplate for what I think is probably a pretty common requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants