Does python's httplib library uses proxy setting from environment variables?

817 views Asked by At

I need to know if httplib library in Python will use the "http_proxy" variable set in my Linux OS environment variables.

1

There are 1 answers

0
Tiger-222 On BEST ANSWER

As you can see in the source code of Lib/httplib.py, there is not call to os.environ which is the way to get/set environment variables, neither to any sort of environment reference. So the answer seems to be: no.

But you can call set_tunnel() using your env vars:

from os import environ
from urlparse import urlparse

url = urlparse(environ['http_proxy'])
conn.set_tunnel(url.hostname, url.port)

There are other attributes like url.username and url.password, see urlparse.