且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Python 在 Windows 中设置代理?

更新时间:2023-09-19 10:00:22

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.