2011-08-04 64 views

回答

3

我会用winreg并直接从the registry查询设置。

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet 
Settings] "MigrateProxy"=dword:00000001 
"ProxyEnable"=dword:00000001 
"ProxyHttp1.1"=dword:00000000 
"ProxyServer"="http://ProxyServername:80" 
"ProxyOverride"="<local>" 

例如,像:

import _winreg 

def getProxy(): 
    proxy = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings") 
    server, type = _winreg.QueryValueEx(proxy, "ProxyServer") 
    enabled, type = _winreg.QueryValueEx(proxy, "ProxyEnable") 
    if enabled: 
     return server 
    return None 
0

不能为你发送请求之前您的应用程序在Windows中设置(手动或程序内)HTTP_PROXY环境变量?这应该注意,您通过urllib2发送的任何请求都是通过Proxy进行的。