如何使用 Python 在 Windows 中设置代理? [英] How to set proxy in Windows with Python?

查看:86
本文介绍了如何使用 Python 在 Windows 中设置代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取当前 Windows 的浏览器代理设置,并将它们设置为一个值?

How can I get the current Windows' browser proxy setting, as well as set them to a value?

我知道我可以通过在 Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer 处查看注册表来做到这一点,但我正在寻找,如果可能的话,不要这样做直接弄乱注册表.

I know I can do this by looking in the registry at Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer, but I'm looking, if it is possible, to do this without messing directly with the registry.

推荐答案

urllib 模块在没有指定代理作为参数或环境变量时自动从注册表中检索设置

urllib module automatically retrieves settings from registry when no proxies are specified as a parameter or in the environment variables

在Windows环境下,如果没有代理设置环境变量,代理设置是从注册表的 Internet 设置部分.

In a Windows environment, if no proxy environment variables are set, proxy settings are obtained from the registry’s Internet Settings section.

请参阅上一篇文章中引用的 urllib 模块的文档.

See the documentation of urllib module referenced in the earlier post.

要设置代理,我假设您需要使用 pywin32 模块并直接修改注册表.

To set the proxy I assume you'll need to use the pywin32 module and modify the registry directly.

这篇关于如何使用 Python 在 Windows 中设置代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆