aiosnow icon indicating copy to clipboard operation
aiosnow copied to clipboard

How to use proxy with aiosnow?

Open SergioBlnc opened this issue 3 years ago • 3 comments

I guess I have to configure it with aiohttp, but I don't see the option in aiosnow client module

SergioBlnc avatar Dec 23 '20 08:12 SergioBlnc

Currently, you'll need to use a custom aiohttp.ClientSession. Something like this should work:

class ProxySession(aiohttp.ClientSession):
    def __init__(self, *args, **kwargs):
        super(ProxySession, self).__init__(*args, trust_env=True, **kwargs)

client = aiosnow.Client(session_cls=ProxySession)
...

The proxy information is then taken from the HTTP_PROXY or HTTPS_PROXY environment variables.

If authentication is required, credentials are read from the ~/.netrc file: https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html

I'll look into simplifying this.

rbw avatar Jan 04 '21 21:01 rbw

Many thanks Rob!!

SergioBlnc avatar Jan 10 '21 21:01 SergioBlnc

I found the following works if you only want to use a proxy for aiosnow and not set the HTTP_PROXY or HTTPS_PROXY environment variables:

class ProxySession(aiohttp.ClientSession):
    async def _request(self, *args, **kwargs):
        return await super()._request(*args, proxy="http://proxy.com", **kwargs)

client = aiosnow.Client(session_cls=ProxySession)
...

jonn26 avatar Apr 02 '21 01:04 jonn26