6

由于代理设置,我在安装 sublime text 3 的包控件时遇到问题,但我需要安装插件。当我getproxy在控制台中这样做时,它会返回我 {} 并且当我尝试在控制台中使用 python 设置代理时

urllib.set_proxy('http://user:password@server:port', 'http')

我用它们的值替换了用户、密码、服务器和端口,但它返回了我

Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'set_proxy'

我该怎么做才能让它发挥作用?我需要安装一个插件。

4

4 回答 4

14

设置包控制以在代理服务器后面工作

您需要在设置中设置代理服务器Package Control

将下面的代码复制并粘贴到一个名为的文件中,该文件Package Control.sublime-settings必须保存在您的User配置文件夹中。这与保存您的USER 文件的文件夹相同。数据目录说明了它在您的操作系统上的位置。IEPreferences.sublime-settings

  • 视窗:%APPDATA%\Sublime Text 3\Packages\User\Package Control.sublime-settings
  • 操作系统:~/Library/Application Support/Sublime Text 3/Packages/User/Package Control.sublime-settings
  • Linux:~/.config/sublime-text-3/Packages/User/Package Control.sublime-settings

显然,您必须在下面的相关字段中添加域和端口以及您的用户名和密码。代理应采用以下形式:proxyserver:port. 例如

{
    "http_proxy": "server.com:80",
    "https_proxy": "server.com:8080",
    "proxy_username": "mynameis",
    "proxy_password": "mypassis",
}

另请参阅:包控制设置

{
    // An HTTP proxy server to use for requests. Not normally used on Windows
    // since the system proxy configuration is utilized via WinINet. However,
    // if WinINet is not working properly, this will be used by the Urllib
    // downloader, which acts as a fallback.
    "http_proxy": "",

    // An HTTPS proxy server to use for requests - this will inherit from
    // http_proxy if it is set to "" or null and http_proxy has a value. You
    // can set this to false to prevent inheriting from http_proxy. Not
    // normally used on Windows since the system proxy configuration is
    // utilized via WinINet. However, if WinINet is not working properly, this
    // will be used by the Urllib downloader, which acts as a fallback.
    "https_proxy": "",

    // Username and password for both http_proxy and https_proxy. May be used
    // with WinINet to set credentials for system-level proxy config.
    "proxy_username": "",
    "proxy_password": "",
}
于 2017-04-30T20:24:22.580 回答
6

您可以简单地在 Sublime 3 控制台中运行以下命令(使用CTRL+` 或启动控制台View -> Show Console

import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler({'http': 'http://USER:PASSWORD@HOST:PORT', 'https': 'https://USER:PASSWORD@HOST:PORT'})) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())

在上面的代码中,您需要根据您的代理详细信息替换和键的值( USER:PASSWORD@HOST:PORThttphttps

然后点击Enter,它将Package Control使用提供的代理安装

于 2018-06-28T06:50:54.267 回答
4

我遇到了同样的问题,我无法下载 Sublime Text 3 的软件包。我在运行时设置了代理服务器,如下面的 Sublime 控制台(Mac 快捷键 Ctrl + `)中的片段所示,它对我有用。

import os
proxy_server = 'http://username:password@proxy_server_name:port'
os.environ['http_proxy'] = proxy_server
os.environ['HTTP_PROXY'] = proxy_server
os.environ['https_proxy'] = proxy_server
os.environ['HTTPS_PROXY'] = proxy_server
os.environ['all_proxy'] = proxy_server
os.environ['ALL_PROXY'] = proxy_server
os.environ['ftp_proxy'] = proxy_server
os.environ['FTP_PROXY'] = proxy_server
于 2019-03-07T10:31:20.883 回答
0

对于socks5代理设置:

菜单栏:Preferences > Package Settings > Package Control > Settings

注意:curl下载器后端支持socks5

{
    
    "downloader_precedence": {
        "linux": ["curl"]
    },
    "http_proxy": "socks5://127.0.0.1:1080",
    "proxy_password": "",
    "proxy_username": "",
...

于 2020-11-23T06:49:07.107 回答