今天 Sublime Text 安装 插件是,提示错误:
Package Control
There are no packages available for installation
Please see https://packagecontrol.io/docs/troubleshooting for help
控制台提示:
Package Control: Attempting to use Urllib downloader due to WinINet error: Error downloading channel. Connection refused (errno 12029) during HTTP write phase of downloading https://packagecontrol.io/channel_v3.json.
Package Control: Error downloading channel. URL error [WinError 10060] 因为链接方在一段时间后没有正确答复或链接的主机没有反应,链接尝试失败。 downloading https://packagecontrol.io/channel_v3.json.
也考虑过最简单的方法,将channel_v3.json 保存到本身的服务器上,修改 Sublime Text 的配置文件。这种缺点也很明显,会和官方插件不一样步(虽然新出的插件页用不到),编写了一个小代理脚本,会两个小时自动同步一次,完美的解决了这个问题。固然,官网服务器加入出现故障时,本脚本不会更新,仍使用本地缓存。
Package Control 不能使用?
使用方法以下(以我我已经部署好的地址为例,若是不放心我,能够在页面底部下载源码自行部署):
1. 打开 Settings User
打开 Sublime Text,选择 references -> Package Setting -> Package Control -> Settings User
2. 输入配置信息 打开配置文件后,输入 channels 信息(请参考页面顶部路径说明 ,以线上地址为例):
1
2
3
|
3. 保存后,Package Control 已经能够正常使用了
Package Control 不能安装?
Package Control 能够安装插件了,在备用机例发现 Package Control 如今居然没法安装成功,这个有点繁琐,还在用同一个脚本也解决了。
安装时的错误提示以下:
Error installing Package Control: HTTPS error encountered, falling back to HTTP –
Error installing Package Control: HTTP error encountered, giving up –
error: An error occurred installing Package ControlPlease check the Console for details
Visit https://packagecontrol.io/installation for manual instructions
那咱们就 顺着 https://packagecontrol.io/installation 向下来。先给本页面代理,并替换安装地址,最终代理后的地址以下: http://www.miaoqiyuan.cn/products/proxy.php/https://packagecontrol.io/installation。
1. 直接访问上面提到的安装地址,获取安装代码
程序会自动替换安装脚本的网络路径,已我已经部署好的地址为例,安装代码为:
1
|
import urllib.request,os,hashlib; h = '6f4c264a24d933ce70df5dedcf1dcaee' + 'ebe013ee18cced0ef93d5f746d80ef60'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://www.miaoqiyuan.cn/products/proxy.php/http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
|
2. 打开Sublime Text 控制台,复制代码安装
打开 Sublime Text,在 View 菜单下,找到 Show Console。在底部控制台复制上面的代码后,按回车,很快就会安装完毕(和官方安装方法一致)。
安装完毕后,别忘了参考上面的教程更改 channels
问题解决,吹吹牛
这样处理后已经能用了,趁如今心情好,顺便吹吹牛,煽煽情:
最为一个中国的开发者,吃饭的家伙常常 由于 墙 的问题 无法使用。
虽然 阿里、网易 的镜像能解决大部分问题,可是对于小众的软件就只没办法了(好比 神器 Sublime Text),每次出问题都把本身折腾的焦头烂额,影响工做进度。好比 Sublime Text,以前从同行的博客分享中找到了 channel_v3.json,他的站点由于备案问题,今天也不能访问了。。。
个人目标是这样项目把全部 小工具因墙出现的问题 都解决了,让中国程序员不怕断网、不怕被墙,开开心心快快乐乐的编码。(无论能不能实现,这个牛先吹着)
代理脚本也很简单,只有60行代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<?php
define(
'CACHE'
,
'./proxy/cache/'
);
define(
'CONFIG'
,
'./proxy/conf/'
);
$url
= isset(
$_SERVER
[
'PATH_INFO'
]) ?
$_SERVER
[
'PATH_INFO'
] :
''
;
$url
=
substr
(
$url
, 1);
//验证请求是否合法
$white
= json_decode(
file_get_contents
(CONFIG .
'white.json'
), true);
$matched
= false;
$verify
= false;
foreach
(
$white
as
$item
) {
if
(preg_match(
$item
[
'pattern'
],
$url
)) {
$matched
= true;
$verify
=
$item
[
'verify'
];
break
;
}
}
if
(!matched) {
header(
'404 Not Found'
);
die
("
<h2>Only whitelisted links are allowed</h2>
");
}
//根据请求获取MIME
$mimes
= json_decode(
file_get_contents
(CONFIG .
'mime-lite.json'
), true);
$ext
=
explode
(
"."
,
$url
);
$ext
=
$ext
[
count
(
$ext
) - 1];
$ext
=
'.'
.
$ext
;
if
(
empty
(
$mimes
[
$ext
])) {
$ext
=
'.html'
;
}
$mime
=
$mimes
[
$ext
];
//缓存文件,两小时更新一次
$cache_file
= CACHE . md5(
$cache
) .
$ext
;
if
(!
is_file
(
$cache_file
)) {
$will_refrech
= true;
}
elseif
(time() -
filemtime
(
$cache_file
) > 7200) {
$will_refrech
= true;
}
else
{
$will_refrech
= false;
}
if
(
$will_refrech
) {
$body
=
file_get_contents
(
$url
);
if
(
empty
(
$verify
) || preg_match(
$verify
,
$body
)) {
file_put_contents
(
$cache_file
,
$body
);
}
}
//输出结果
if
(
is_file
(
$cache_file
)) {
header(
"Content-Type: ${mime}"
);
header(
"Last-Modified:"
.
gmdate
(
"D, d M Y H:i:s"
,
filemtime
(
$cache_file
)) .
" GMT"
);
header(
"Content-Length:"
.
filesize
(
$cache_file
));
echo
file_get_contents
(
$cache_file
);
}
else
{
header(
'404 Not Found'
);
die
("
<h2>Server Error!</h2>
");
}
|
项目已经在 Gitee.com 开源,能够直接去 https://gitee.com/mqycn/Proxy-for-Chinese-programmer/ 下载。
已经实现:
一、支持自动更新 虽然以前可使用,可是由于 是手工保存到服务器静态文件,只能使用老的插件。如今设置的每两小时更新一次
二、在官网出现故障时仍能访问 在自动和官网同步时,会 判断 官网是否返回正确的代码
三、一套最好能支持多个代理 借用 PHP 的PATH_INFO,能够很是方面的传入任何 URL,能够对全网实现代理。固然,本程序也提供了白名单。
固然代理是有前提的:
一、对于被墙的代理,必须将域名放到 境外服务器
二、对于Sublime Text,服务器必须支持 IPv6
白名单设置说明
配置文件在: proxy/conf/white.json
1
2
3
4
5
6
7
8
9
10
|
[
{
"pattern"
:
"/https\\:\\/\\/packagecontrol\\.io\\/channel_v3\\.json/"
,
"verify"
:
"/\"repositories\"/"
},
{
"pattern"
:
"网址正则正则表达式,只有在列表中匹配到的url才能够访问"
,
"verify"
:
"内容正则正则表达式,只有返回的内容能匹配本规则,才会写入缓存。也能够为false,不判断直接写入缓存"
},
]
|