Syntax highlighting of 9166627 ~( python/troubleshooting)
= Troubleshooting = <<TableOfContents()>> == requests == === certificate verify failed: unable to get local issuer certificate === Выполняем запрос на корпоративный сервер и получаем ошибку {{{#!highlight python import requests requests.get("https://corp.example.com") # ... # certificate verify failed: unable to get local issuer certificate }}} Проверяем, что проблема в сертификате. Отключаем проверку корневого сертификата и ошибку не получаем {{{#!highlight python requests.get("https://corp.example.com", verify=False) }}} Если указать путь к файлу сертификату CorpCA.cer, то ошибка будет аналогичная. {{{#!highlight python requests.get("https://corp.example.com", verify="./CorpCA.cer") # ... # certificate verify failed: unable to get local issuer certificate }}} Для данного Python-модуля необходимо передавать ''связку (bundle) сертификатов'' . [[https://levelup.gitconnected.com/solve-the-dreadful-certificate-issues-in-python-requests-module-2020d922c72f]] . [[https://www.emaro-ssl.ru/blog/zashchita-sayta-ssl/ca_bundle/]] Связка представляет собой файл, в котором перечислены все сертификаты от корневого до промежуточного в обратном порядке. Если передать связку в метод запроса, ошибка уходит. {{{#!highlight bash cat CorpCA.cer > CA_bundle.cer cat RootCA.cer >> CA_bundle.cer }}} {{{#!highlight python requests.get("https://corp.example.com", verify="./CA_bundle.cer") }}} == pipenv == === AttributeError: module 'collections' has no attribute 'MutableMapping' === При выполнении любой команды `pipenv` получаем {{{#!highlight bash File "/usr/bin/pipenv", line 33, in <module> sys.exit(load_entry_point('pipenv==11.9.0', 'console_scripts', 'pipenv')()) File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) # ... File "/usr/lib/python3/dist-packages/pipenv/vendor/requests/cookies.py", line 172, in <module> class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping): }}} Возможные причины проблемы описаны здесь https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1012124 Решение - обновление pipenv {{{#!highlight bash pip install --upgrade pipenv }}} === pipenv install: FileNotFoundError: [Errno 2] No such file or directory === В Ubuntu 22.04 при установке окружения получаем ошибку {{{#!highlight bash pipenv install # ... # ✔ Successfully created virtual environment! # ... # FileNotFoundError: [Errno 2] No such file or directory: '/home/zoid/.local/share/virtualenvs/pod-assistant-naOJxlf6/bin/python' }}} Есть похожая проблема в WSL - https://github.com/microsoft/WSL/issues/8327 Решение {{{ SETUPTOOLS_USE_DISTUTILS=stdlib pipenv install }}} == system == === AttributeError: 'Thread' object has no attribute 'isAlive' === После обновления Ubuntu появилась ошибка {{{#!highlight bash sudo add-apt-repository ppa:appimagelauncher-team/stable ... Traceback (most recent call last): File "/usr/bin/add-apt-repository", line 191, in <module> if not sp.add_source_from_shortcut(shortcut, options.enable_source): File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 777, in add_source_from_shortcut if worker.isAlive(): AttributeError: 'Thread' object has no attribute 'isAlive' }}} Проблема в том, что метод `isAlive()` в python3.9 переименован в `is_alive()`, но в ''dist-packages'' это изменение не прошло. Поэтому пробуем править исходники {{{#!highlight bash vim /usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py :777 }}} === ModuleNotFoundError: No module named 'apt_pkg' === После обновления python на версию 3.9 команда `apt update` выдает ошибку {{{#!highlight bash ... Получено 265 kB за 1с (214 kB/s) Traceback (most recent call last): File "/usr/lib/cnf-update-db", line 8, in <module> from CommandNotFound.db.creator import DbCreator File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 11, in <module> import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' Чтение списков пакетов… Готово E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi' E: Sub-process returned an error code }}} Решение может быть найдено здесь - https://www.datasciencelearner.com/importerror-no-module-named-apt_pkg-fix/ {{{#!highlight bash cd /usr/lib/python3/dist-packages sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so }}}
