Skip to content Skip to sidebar Skip to footer

How Does One Specify The Equivalent Of `--proxy-headers` Curl Argument Into Requests?

I'm looking to pass some headers only into my proxies as I'm using requests, and I don't see a method to do it. the urllib3.ProxyManager has a proxy_headers parameter, so I would a

Solution 1:

You can do it with a customized HTTPAdapter (for example like the following):

importrequestsproxyheaders= { 'http://proxy.that.needs.header:8080/': { 'ProxyHeader1': 'SomeValue', 'ProxyHeaderN': 'OtherValue' } }

classProxyHeaderAwareHTTPAdapter(requests.adapters.HTTPAdapter):
    def proxy_headers(self, proxy):
        if proxy in proxyheaders:
            return proxyheaders[proxy]
        else:
            returnNones= requests.Session()
s.mount('http://', ProxyHeaderAwareHTTPAdapter())
s.mount('https://', ProxyHeaderAwareHTTPAdapter())
s.get(....)
...

You could also directly create and return a configured urllib3.ProxyManager if You overwrite the proxy_manager_for methos instead of proxy_headers if You like. https://requests.kennethreitz.org/en/master/api/#requests.adapters.HTTPAdapter

Post a Comment for "How Does One Specify The Equivalent Of `--proxy-headers` Curl Argument Into Requests?"