【问题标题】:Which Python module to use to access the Proxy setting of Windows 7?使用哪个 Python 模块来访问 Windows 7 的代理设置?
【发布时间】:2011-08-04 03:14:02
【问题描述】:

我是 Python 新手,想编写一个脚本来根据我连接的网络更改 Windows 代理设置。我可以使用任何现有的 python 模块吗?感谢您的帮助。

谢谢, 瑟图

【问题讨论】:

    标签: python windows proxy


    【解决方案1】:

    我会使用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
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-26
        相关资源
        最近更新 更多