使用哪个Python模块访问Windows 7的代理设置?

我是Python的新手,想写一个脚本来改变基于我连接的networking的Windows代理设置。 是否有任何现有的Python模块,我可以使用? 感谢你的帮助。

谢谢,Sethu

我会使用winreg并直接从注册表中查询设置。

  [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 

在发送请求之前,您是否可以在Windows中为应用程序设置HTTP_PROXY环境变量(手动或在您的程序中)? 这应该注意,您通过urllib2发送的任何请求通过代理。