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

How to use proxy with aiosnow? #103

Open
SergioBlnc opened this issue Dec 23, 2020 · 3 comments
Open

How to use proxy with aiosnow? #103

SergioBlnc opened this issue Dec 23, 2020 · 3 comments

Comments

@SergioBlnc
Copy link

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

@rbw
Copy link
Owner

rbw commented Jan 4, 2021

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.

@SergioBlnc
Copy link
Author

Many thanks Rob!!

@jonn26
Copy link

jonn26 commented Apr 2, 2021

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)
...

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

3 participants