urllib.error.URLError: <urlopen error [SSL: WRONG

urllib.error.URLError: <urlopen error [SSL: WRONG,第1张

方法总共记录了四种
其一是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 ssl
ssl._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
参考https://zhuanlan.zhihu.com/p/128545659

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/714357.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-24
下一篇 2022-04-24

发表评论

登录后才能评论

评论列表(0条)

保存