python urllib2 can open localhost but not

Set a no_proxy or NO_PROXY environment key with, optionally with localhost too:

import os

os.environ['no_proxy'] = ',localhost'

On Windows the ProxyOverride key in the HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings registry is consulted as well, you probably have localhost registered as exception. Check your proxy settings to verify this.

Leave a Comment