debian下使用Sphinx異常“Could not import extension sphinx.builders.linkcheck (exception: cannot import name SSLError)”的解決,debiansphinx

來源:互聯網
上載者:User

debian下使用Sphinx異常“Could not import extension sphinx.builders.linkcheck (exception: cannot import name SSLError)”的解決,debiansphinx

最近使用到Sphinx編譯文檔,出現如下異常:

Extension error:
Could not import extension sphinx.builders.linkcheck (exception: cannot import name SSLError)

一開始有點摸不著頭腦,明明是不能匯入“sphinx.builders.linkcheck”,錯誤資訊卻是“cannot import name SSLError”

於是使用“-P”參數在異常時開啟pdb調試,pdb列印資訊如下:

Exception occurred while building, starting debugger:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/Sphinx-1.5b1-py2.7.egg/sphinx/cmdline.py", line 295, in main
opts.warningiserror, opts.tags, opts.verbosity, opts.jobs)
File "/usr/local/lib/python2.7/dist-packages/Sphinx-1.5b1-py2.7.egg/sphinx/application.py", line 189, in __init__
self.setup_extension(extension)
File "/usr/local/lib/python2.7/dist-packages/Sphinx-1.5b1-py2.7.egg/sphinx/application.py", line 514, in setup_extension
err)
ExtensionError: Could not import extension sphinx.builders.linkcheck (exception: cannot import name SSLError)

可以看到出錯的地方在“application.py”,於是開啟該檔案一探究竟,源碼如下:

進一步在pdb列印“extension”和“err”

現在可以知道,是在import的時候遇到了importerror,但是不知道具體是哪裡錯了,乾脆另起python命令列,直接import這個擴充“sphinx.builders.linkcheck”,結果出現如下錯誤:

可以看到錯誤原因是不能從“requests.packages.urllib3.exceptions”匯入“SSLError”,經驗證發現,可以在“requests.exceptions”裡面匯入“SSLError”

而網上搜尋,大多也只是提到從“requests.exceptions”匯入“SSLError”。由於Sphinx是剛下載的最新版,我懷疑可能是版本不相容的問題。

查看requests版本發現requests確實不是最新版本(官網目前最新版本為:v2.12.1):

進一步上官網確認,發現官網上有關SSLError的代碼確實已經發生變化:

到此,完全確認是requests版本更新過程中改變了“SSLError”的位置(匯入方式),升級requests到最新版後問題解決。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.