How do you use an HTTP/HTTPS proxy with boto3?

后端 未结 4 2077
北海茫月
北海茫月 2021-01-01 11:58

On the old boto library is was simple enough to use the proxy, proxy_port, proxy_user and proxy_pass paramet

4条回答
  •  误落风尘
    2021-01-01 12:35

    Apart from altering the environment variable, I'll present what I found in the code.

    Since boto3 uses botocore, I had a look through the source code:

    https://github.com/boto/botocore/blob/66008c874ebfa9ee7530d944d274480347ac3432/botocore/endpoint.py#L265

    From this link, we end up at:

        def _get_proxies(self, url):
            # We could also support getting proxies from a config file,
            # but for now proxy support is taken from the environment.
            return get_environ_proxies(url)
    

    ...which is called by proxies = self._get_proxies(final_endpoint_url) in the EndpointCreator class.

    Long story short, if you're using python2 it will use the getproxies method from urllib2 and if you're using python3, it will use urllib3.

    get_environ_proxies is expecting a dict containing {'http:' 'url'} (and I'm guessing https too).

    You could always patch the code, but that is poor practice.

提交回复
热议问题