python-twitch-client icon indicating copy to clipboard operation
python-twitch-client copied to clipboard

Proxy support

Open tonycpsu opened this issue 6 years ago • 0 comments

I'm developing a console application to browse and watch Twitch streams (among other things) and would like to see if there's any interest in a PR that would add HTTPS proxy support. The requests library can already read from the HTTP_PROXY and HTTPS _PROXY variables, but sometimes it's preferable to set proxies on the fly (in application configuration) instead of in the shell environment before the program is started.

My thinking is this: instead of calling requests.get(), requests.post(), etc., the API objects could use a requests.Session() object, which could either come from the calling application as a parameter, or, if not provided, be created. In the v5 API, it looks something like this

    def __init__(self, client_id, oauth_token=None, session=None):
        """Initialize the API."""
        super(TwitchAPI, self).__init__()
        self._session = session or requests.Session()

Then, the _request_get, _request_post, etc. methods would do the following:

response = self._session.get(url, params=params, headers=headers)

I figured since I'm doing this work anyway, it might be useful as a PR. Thoughts?

tonycpsu avatar Jan 19 '19 04:01 tonycpsu