600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > urllib.error.URLError: <urlopen error [SSL: WRONG_VERSION_NUMBER] wrong version number 成功解决

urllib.error.URLError: <urlopen error [SSL: WRONG_VERSION_NUMBER] wrong version number 成功解决

时间:2019-05-14 07:36:48

相关推荐

urllib.error.URLError: <urlopen error [SSL: WRONG_VERSION_NUMBER] wrong version number 成功解决

方法总共记录了四种

其一是SSL证书问题。

可以采用以下代码打开该url

import ssl# This restores the same behavior as before.context = ssl._create_unverified_context()response = urllib.request.urlopen("https://no-valid-cert", context=context)

以上方法中的https://no-valid-cert可以换成你自己想要的网址

其二是把https改为http,因为python的一些版本在当你urllib.urlopen一个 https 的时候会验证一次 SSL 证书。

其三是在出现问题的代码位置

加上

import sslssl._create_default_https_context = ssl._create_unverified_context

我就是在调用python 3.8.0自带的urllib库中的命令时的py文件中加的

model = ALBEF(config=config, text_encoder=args.text_encoder, tokenizer=tokenizer, init_deit=True)

也就是这里模型初始化(init_deit)的时候,调用python 3.8下的 lib/python3.8/http/client.py中的return self.sslsocket_class._create出现了该error,但在初始化model的py文件一开始加上这两句就没问题了

其四也是最终方案

升级你的python解释器版本,如2.7或者3.7升成3.8甚至3.9

参考/p/128545659

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。