mac软件问题和优化-旧版sublime的插件包下载失败

github 最近禁用了 tls1.0 加密协议,而此时mac系统上,旧版sublime,下载时会出现报错。查看sublime控制台报错信息:

Package info was unavailable last time crawler ran. Error downloading repository. HTTP exception InvalidCertificateException (Host api.github.com returned an invalid certificate ([SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:548))) downloading https://api.github.com/repos/rust-lang/sublime-rust.

然后查到:github 的问题贴

简单来说就是,mac版 sublime 用的下载模块是 urllib ,而urllib 是python自带的标准库,里面有ssl模块。而旧版python的ssl模块,采用ssl1.0连接服务器,所以导致高版本的ssl服务器拒绝连接。

解决办法是:打开sublime的
preferences->Package settings->Package control->Settings – User
添加如下代码:【也就是知道下载模块的第一优先级是使用 crul 模块】

"downloader_precedence":
	{
		"osx":
		[
			"curl",
			"urllib",
			"wget"
		]
	},

urllib是Python自带的标准库,无需安装,直接可以用。
提供了如下功能:

  • 网页请求
  • 响应获取
  • 代理和cookie设置
  • 异常处理
  • URL解析

爬虫所需要的功能,基本上在urllib中都能找到,学习这个标准库,可以更加深入的理解后面更加便利的requests库。

python 2.7  代码使用如下:

# request:GET
import urllib
response = urllib.urlopen('http://www.baidu.com')
print(response.read().decode('utf-8'))

英文问题讨论解析:


The problem is that the crawler is running on an old OS and Python 3.3, which doesn’t support TLS 1.2. wbond is already on it.

=====================================================

Python 3.3’s _ssl module uses the OpenSSL API in such a way that a connection to a TLS 1.2 server is not possible. It doesn’t use the TLS 1.1 or TLS 1.2 constants, but rather a constant for TLS 1.0. This results in GitHub rejecting the connection since it uses an insecure version of the TLS protocol.

Windows users by default use the WinInetDownloader, which uses the wininet library, and Microsoft’s TLS stack, so as long as they are running a recent build of Windows, they will have TLS 1.2.

Mac and Linux users default to using urllib, which utilizes the Python _ssl module.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments