juypter notebook启动ssl报错的处理记录

错误信息如下:

(d2l) D:\coding\deep_learn\d2l-zh\pytorch>jupyter notebook

Traceback (most recent call last):

File "D:\software_env\anaconda3\envs\d2l\lib\runpy.py", line 194, in _run_module_as_main

return _run_code(code, main_globals, None,

File "D:\software_env\anaconda3\envs\d2l\lib\runpy.py", line 87, in _run_code

exec(code, run_globals)

File "D:\software_env\anaconda3\envs\d2l\Scripts\jupyter-notebook.EXE\main.py", line 4, in <module>

File "D:\software_env\anaconda3\envs\d2l\lib\site-packages\notebook\notebookapp.py", line 59, in <module>

from tornado import httpserver

File "<frozen importlib._bootstrap>", line 1039, in _handle_fromlist

File "D:\software_env\anaconda3\envs\d2l\lib\site-packages\tornado\init.py", line 66, in getattr

return importlib.import_module("." + name, name)

File "D:\software_env\anaconda3\envs\d2l\lib\importlib\init.py", line 127, in import_module

return _bootstrap._gcd_import(namelevel:, package, level)

File "D:\software_env\anaconda3\envs\d2l\lib\site-packages\tornado\httpserver.py", line 32, in <module>

from tornado.http1connection import HTTP1ServerConnection, HTTP1ConnectionParameters

File "D:\software_env\anaconda3\envs\d2l\lib\site-packages\tornado\http1connection.py", line 34, in <module>

from tornado import iostream

File "<frozen importlib._bootstrap>", line 1039, in _handle_fromlist

File "D:\software_env\anaconda3\envs\d2l\lib\site-packages\tornado\init.py", line 66, in getattr

return importlib.import_module("." + name, name)

File "D:\software_env\anaconda3\envs\d2l\lib\importlib\init.py", line 127, in import_module

return _bootstrap._gcd_import(namelevel:, package, level)

File "D:\software_env\anaconda3\envs\d2l\lib\site-packages\tornado\iostream.py", line 40, in <module>

from tornado.netutil import ssl_wrap_socket, _client_ssl_defaults, _server_ssl_defaults

File "D:\software_env\anaconda3\envs\d2l\lib\site-packages\tornado\netutil.py", line 35, in <module>

_client_ssl_defaults = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)

File "D:\software_env\anaconda3\envs\d2l\lib\ssl.py", line 750, in create_default_context

context.load_default_certs(purpose)

File "D:\software_env\anaconda3\envs\d2l\lib\ssl.py", line 574, in load_default_certs

self._load_windows_store_certs(storename, purpose)

File "D:\software_env\anaconda3\envs\d2l\lib\ssl.py", line 566, in _load_windows_store_certs

self.load_verify_locations(cadata=certs)

ssl.SSLError: ASN1: NOT_ENOUGH_DATA not enough data (_ssl.c:4194)

通过conda安装深度学习框架出现错误,参考 https://blog.csdn.net/xeqja/article/details/162229894 的解释,大概是证书过多导致python启动相关的证书逻辑出现错误

解决方法:

将原来旧的代码进行替换

这是旧的代码

python 复制代码
def _load_windows_store_certs(self, storename, purpose):
    certs = bytearray()
    try:
        for cert, encoding, trust in enum_certificates(storename):
            if encoding == "x509_asn":
                if trust is True or purpose.oid in trust:
                    certs.extend(cert)
    except PermissionError:
        warnings.warn("unable to enumerate Windows certificate store")
    return certs

替换为新的代码

python 复制代码
def _load_windows_store_certs(self, storename, purpose):
    certs = bytearray()
    try:
        for cert, encoding, trust in enum_certificates(storename):
            if encoding == "x509_asn":
                if trust is True or purpose.oid in trust:
                    try:
                        certs.extend(cert)
                    except Exception:
                        continue  # 跳过坏证书
    except PermissionError:
        warnings.warn("unable to enumerate Windows certificate store")
    return certs

替换成功后的截图:

注意点

替换的ssl.py是你通过conda安装后对应环境的,并不是conda的,如果只替换conda下的脚本,启动的时候,大概率还是有问题

如果对应python版本升级的话,也要注意对应的脚本会不会被替换

相关推荐
默_笙4 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
qq_426003964 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫4 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技4 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读4 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时4 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
奇思妙想聪明勤奋的小羊4 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd1234 天前
2026年第38周GitHub趋势周报
python·科技·github
IZero074 天前
Jev 与 Laya
python·语言模型