aiosnow
aiosnow copied to clipboard
How to use proxy with aiosnow?
I guess I have to configure it with aiohttp, but I don't see the option in aiosnow client module
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.
Many thanks Rob!!
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)
...