Recently, I’ve been trying to wrap my head around using Python tools behind a proxy. I found that the documentation specific to Mac OS X was sparse so I decided to post my findings.

First, if you’ve configured proxy settings in System Preferences you’ll find that urllib2 retrieves your settings using the ‘OS X System Configuration Framework’:
>>> import urllib
>>> urllib.getproxies()

{'http': '', 'https': ''}

You can use an opener with urllib2 to handle your own proxy settings:
>>> import urllib2
>>> request = urllib2.Request('')

>>> proxy_handler = urllib2.ProxyHandler({'http': '', 'https': ''})

>>> opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1), proxy_handler)

Lastly, Python also honors your bash proxy exports, including ‘no_proxy’ settings:
export {http,https,ftp}_proxy=''
export no_proxy=''

>>> import urllib
>>> urllib.getproxies()
{'ftp': '', 'http': '', 'https': '', 'no': ''}

And of course, read the docs to learn more: