メンテナンス・トラブルシュート - SSL 無料証明書 - トラブルシュート - RequestsDependencyWarning: urllib3 (1.23) or chardet (3.0.4)

 
1. 概要
2. リストを確認
3. バージョンを確認
4. urllib3 を更新
5. ports で再インストール(一件落着?)

1. 概要

 2018年12月08日に、証明書の更新でエラーが発生しております。  コマンドで起動してみると

> /usr/local/bin/certbot renew --standalone --pre-hook "/usr/local/etc/rc.d/apache24 stop" --post-hook "/usr/local/etc/rc.d/apache24 start"
/usr/local/lib/python3.6/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.23) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

No renewals were attempted.
No hooks were run.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 素直に読めば urllib3 (1.23) か chardet (3.0.4) がサポートしているバージョンではないっていうことでっしゃろ?

2. リストを確認

 pip で確認してみます。

> pip list
Package                  Version
------------------------ ----------
acme                     0.29.1
alabaster                0.7.6
apache-libcloud          2.4.0

・・・	略	・・・

certifi                  2018.11.29
cffi                     1.11.5
chardet                  3.0.4
ConfigArgParse           0.13.0
configobj                5.0.6

・・・	略	・・・

msgpack                  0.5.6
parsedatetime            2.4
pbr                      4.0.4
pip                      10.0.1
post                     1.0.2
progressbar              2.5
public                   1.0.3

・・・	略	・・・

pycparser                2.18
pycrypto                 2.6.1
Pygments                 2.3.0

sphinx-rtd-theme         0.4.0
sphinxcontrib-websupport 1.0.1
tornado                  4.5.3

・・・	略	・・・

urllib3                  1.23
zope.component           4.4.1
zope.event               4.3.0
zope.interface           4.6.0
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
 最後のメッセージを読んでまずは、pip 自体を更新

> pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
    100% |????????????????????????????????| 1.3MB 1.5MB/s
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-18.1

3. バージョンを確認

 モジュールのバージョンを見てみます。  urllib3 は

> pip search urllib3
urllib3-mock (0.3.3)         - A utility library for mocking out the `urllib3` Python library.
urllib3 (1.24.1)             - HTTP library with thread-safe connection pooling, file post, and more.
  INSTALLED: 1.23
  LATEST:    1.24.1
opbeat_python_urllib3 (1.1)  - An urllib3 transport for Opbeat
httplib2shim (0.0.3)         - A wrapper over urllib3 that matches httplib2's interface
srv-hijacker (0.0.5)         - Patch urllib3 to query a certain DNS server for SRV records
apiclient (1.0.3)            - Framework for making good API client libraries using urllib3.
 chardet は

> pip search chardet
chardet (3.0.4)  - Universal encoding detector for Python 2 and 3
  INSTALLED: 3.0.4 (latest)
charset (1.0.1)  - Clases for charset detection. Uses chardet and mozilla universal charset detection.
 ってことは urllib3 だけ更新すればいいのかな?

4. urllib3 を更新


> pip install -U urllib3
Collecting urllib3
  Downloading https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl (118kB)
    100% |????????????????????????????????| 122kB 2.0MB/s
requests 2.19.1 has requirement urllib3<1.24,>=1.21.1, but you'll have urllib3 1.24.1 which is incompatible.
Installing collected packages: urllib3
  Found existing installation: urllib3 1.23
    Uninstalling urllib3-1.23:
      Successfully uninstalled urllib3-1.23
Successfully installed urllib3-1.24.1
 朱書きしたところは、本当に赤く表示されています(気になるなぁ)。  urllib3-1.24.1 にはなりましたが・・・。  certbot を起動してみると

> /usr/local/bin/certbot renew --standalone --pre-hook "/usr/local/etc/rc.d/apache24 stop" --post-hook "/usr/local/etc/rc.d/apache24 start"
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 581, in _build_master
    ws.require(__requires__)
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 898, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 789, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (urllib3 1.24.1 (/usr/local/lib/python3.6/site-packages), Requirement.parse('urllib3<1.24,>=1.21.1'), {'requests'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/certbot", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3126, in <module>
    @_call_aside
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3110, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3139, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 583, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 596, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 784, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'urllib3<1.24,>=1.21.1' distribution was not found and is required by requests
 いあいあこれは・・・。  「urllib3<1.24,>=1.21.1」ってのは「1.24 より小さくて 1.21.1 より大きくなければだめ」って言っているのでは?  pkg を見てみる。

> pkg search urllib3
py27-urllib3-1.22,1            HTTP library with thread-safe connection pooling, file post, and more
py36-urllib3-1.22,1            HTTP library with thread-safe connection pooling, file post, and more

/usr/ports/net/py-urllib3/Makefile
 を見てみる(先頭のほうだけね)。

# Created by: Olivier Duchateau
# $FreeBSD: head/net/py-urllib3/Makefile 472884 2018-06-20 17:05:41Z mat $

PORTNAME=       urllib3
PORTVERSION=    1.22
PORTEPOCH=      1
CATEGORIES=     net python
MASTER_SITES=   CHEESESHOP
PKGNAMEPREFIX=  ${PYTHON_PKGNAMEPREFIX}

MAINTAINER=     python@FreeBSD.org
COMMENT=        HTTP library with thread-safe connection pooling, file post, and more

LICENSE=        MIT
LICENSE_FILE=   ${WRKSRC}/LICENSE.txt
 pkg のバージョンを見てみる。

> pkg version -v -n py36-urllib3
py36-urllib3-1.22,1                =   up-to-date with index
 とりあえず、pip の urllib3 をアンインストールしてみます。

> pip uninstall urllib3
Uninstalling urllib3-1.24.1:
  Would remove:
    /usr/local/lib/python3.6/site-packages/urllib3-1.24.1.dist-info/*
    /usr/local/lib/python3.6/site-packages/urllib3/*
Proceed (y/n)? 											←	y Enter
  Successfully uninstalled urllib3-1.24.1
 これで実行してみると

> /usr/local/bin/certbot renew --standalone --pre-hook "/usr/local/etc/rc.d/apache24 stop" --post-hook "/usr/local/etc/rc.d/apache24 start"
Traceback (most recent call last):
  File "/usr/local/bin/certbot", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3126, in <module>
    @_call_aside
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3110, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3139, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 581, in _build_master
    ws.require(__requires__)
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 898, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 784, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'urllib3<1.24,>=1.21.1' distribution was not found and is required by requests
 今度はないって言いやがる!

5. ports で再インストール(一件落着?)

 こういうときの最後の手段は、pkg か ports で再インストールですね。  今回は ports で

cd /usr/ports/net/py-urllib3
make deinstall clean
make
make install
 その後

> /usr/local/bin/certbot renew --standalone --pre-hook "/usr/local/etc/rc.d/apache24 stop" --post-hook "/usr/local/etc/rc.d/apache24 start"
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

No renewals were attempted.
No hooks were run.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 エラーは出なくなりました。  これで一件落着かしら?
 
 
カウンタバックグラウンド